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

实在不明白answer 都wrong在哪里了?

Posted by cary1988 at 2010-05-01 17:04:10 on Problem 1503
#include"iostream"
using namespace std;
void add(int sum[],char num[])
{
	int l=strlen(num);
	for(int i=0;i<l;i++)
	{
		sum[l-i-1]+=num[i]-'0';
	}
}
void output(int sum[])
{
	int i=2000-1;
	while(sum[i]==0&&i>=0)
		i--;
	if(i==-1)
	{
		cout<<"0"<<endl;
		return;
	}
	for(int j=0;j<=i;j++)
	{
		sum[j+1]+=sum[j]/10;
		sum[j]=sum[j]%10;
	}
	i++;
	while(sum[i]!=0)
	{
		sum[i+1]+=sum[i]/10;
		sum[i]=sum[i]%10;
		i++;
	}
	for(int t=i-1;t>=0;t--)
	{
		cout<<sum[t];
		sum[t]=0;
	}
	cout<<endl;

}
int main()
{
	int n;
	char ch;
	cin>>n;
	int sum[2000]={0};
	while(n)
	{
		
		char num[2000]={0};
		cin>>num;
		if(num[0]!='0'||num[1]!=0)
		{
			add(sum,num);
		}
		else
		{
			output(sum);
				
			n--;
			if(n!=0)
				cout<<endl;
		}
		
	}
	return 0;
}

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