标签:
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 5 int main() 6 { 7 //freopen("in.txt","r",stdin); 8 char s[105]; 9 int a[1005],b[1005]; 10 int t,j,i; 11 scanf("%d",&t); 12 while(t--) 13 { 14 memset(a,0,sizeof(a)); 15 while(scanf("%s",s)&&strcmp(s,"0")!=0) 16 { 17 memset(b,0,sizeof(b)); 18 int len=strlen(s); 19 for(j=0,i=len-1;i>=0;i--) 20 b[j++]=s[i]-‘0‘; 21 for(i=0;i<1005;i++) 22 { 23 a[i]+=b[i]; 24 if(a[i]>=10) 25 { 26 a[i]-=10; 27 a[i+1]+=1; 28 } 29 } 30 } 31 for(i=1004;i>=0;i--) 32 if(a[i])break; 33 if(i==-1) 34 printf("0"); 35 for(;i>=0;i--) 36 printf("%d",a[i]); 37 printf("\n"); 38 if(t!=0) 39 printf("\n"); 40 } 41 return 0; 42 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4674190.html