标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15221 Accepted Submission(s): 3912
#include<stdio.h> #include<string.h> #define MAX 510 #define max(x,y)(x>y?x:y) char s1[MAX]; int a[MAX],b[MAX]; int main() { int n,m,j,i,s,t,l1,k,ok; int len; scanf("%d",&t); while(t--) { ok=0; memset(b,0,sizeof(b)); while(scanf("%s",s1)) { if(s1[0]==‘0‘) break; ok++; memset(a,0,sizeof(a)); l1=strlen(s1); for(i=l1-1,j=0;i>=0;i--) { a[j]=s1[i]-‘0‘; j++; } for(i=0;i<MAX;i++) { b[i]+=a[i]; if(b[i]>=10) { b[i]-=10; b[i+1]++; } } } if(!ok) printf("0\n"); else { for(i=MAX-1;i>=0;i--) if(b[i]!=0) break; for(;i>=0;i--) printf("%d",b[i]); printf("\n"); } if(t) printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4674408.html