标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 261413 Accepted Submission(s): 50581
2 1 2 112233445566778899 998877665544332211
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
#include <stdio.h> #include <string.h> #define N 10005 char a[N],b[N]; int c[N],d[N]; int main() { int n,i,j,k,len1,len2; scanf("%d",&n); k=n; while(n--) { memset(c,0,sizeof(c));//每次都得清零,所以得放到while循环里面! memset(d,0,sizeof(d)); getchar(); scanf("%s%s",a,b);//空格也是scanf的分割符! len1=strlen(a); len2=strlen(b); for(i=len1-1,j=0;i>=0;i--)//因为需要逆序保存,所以应该设变量j从0开始! c[j++]=a[i]-'0'; for(i=len2-1,j=0;i>=0;i--) d[j++]=b[i]-'0'; for(i=0;i<1001;i++) { c[i]+=d[i]; if(c[i]>=10) { c[i]-=10; c[i+1]++; } } printf("Case %d:\n%s + %s = ",k-n,a,b); for(i=1000;i>=0&&c[i]==0;i--); if(i>=0) for(;i>=0;i--) { printf("%d",c[i]); } else printf("0"); printf("\n"); if(n!=0) printf("\n"); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/dxx_111/article/details/47069137