2 1 2 112233445566778899 998877665544332211
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
#include<stdio.h> #include<string.h> int main() { int n,i,j,t,p,q,d,k; char a[1010],b[1010]; int c[1010]; scanf("%d",&n); //getchar(); for(t=1;t<=n;t++) { scanf("%s%s",a,b); p=strlen(a); q=strlen(b); d=0; for(i=p-1,j=q-1,k=0;i>=0&&j>=0;i--,j--,k++) { d+=a[i]-'0'+b[j]-'0'; c[k]=d%10; d/=10; } if(k==p) { while(j>=0) { d+=b[j]-'0'; c[k]=d%10; d/=10; j--;k++; } } else { while(i>=0) { d+=a[i]-'0'; c[k]=d%10; d/=10; i--;k++; } } if(d!=0) { c[k]=d; k++; } printf("Case %d:\n",t); printf("%s + %s = ",a,b); for(i=k-1;i>=0;i--) printf("%d",c[i]); printf("\n"); if(t!=n)//此处就是控制的条件 printf("\n"); } return 0; }
杭电 1002 A + B Problem II(大数处理),布布扣,bubuko.com
杭电 1002 A + B Problem II(大数处理)
原文地址:http://blog.csdn.net/ice_alone/article/details/38640027