| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
why runtime err?#include <iostream>
#include <vector>
#include <string>
using namespace std;
void twoTo10(vector<int> &re,int index);
vector<int> storeNum;
void g2b(int index)
{
if (storeNum.size()-1==index) {
return;
}
if (storeNum[index]==0) {
g2b(index+1);
}
else{
g2b(index+1);
int i;
for(i=index+1;i<storeNum.size();i++)
{
storeNum[i]=1-storeNum[i];
}
}
}
void main()
{
int n;
cin>>n;
storeNum.resize(n);
int i;
for(i=0;i<n;i++)
cin>>storeNum[i];
g2b(0);
// for(i=0;i<n;i++)
// cout<<storeNum[i];
storeNum.erase(storeNum.end()-1);
vector<int> re;
twoTo10(re,storeNum.size()-1);
for(i=0;i<re.size();i++)
cout<<re[i];
cout<<endl;
}
void twoTo10(vector<int> &re,int index)
{
if (index==0) {
// re.clear();
re.push_back(storeNum[0]);
return;
}
// re.clear();
twoTo10(re,index-1);
int carry=storeNum[index];
int k;
for(k=re.size()-1;k>=0;k--)
{
int s = re[k]*2+carry;
int y=s%10;
carry=s/10;
re[k]=y;
}
if (carry==0) {
return;
}else{
re.insert(re.begin(),carry);
return;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator