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 |
实在不明白answer 都wrong在哪里了?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator