Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why runtime err?

Posted by ggg at 2007-05-16 20:48:50 on Problem 1090
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator