A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 120188 Accepted Submission(s): 22865
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
2 1 2 112233445566778899 998877665544332211
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
View Code
1 #include2 #include 3 #define maxn 1010 4 int shu1[maxn],shu2[maxn]; 5 char str1[maxn],str2[maxn]; 6 int main() 7 { 8 int n,i,j,len1,len2,k; 9 scanf("%d",&n);10 getchar();11 for(k=1;k<=n;k++)12 {13 scanf("%s",str1);14 scanf("%s",str2);15 printf("Case %d:\n%s + %s = ",k,str1,str2);16 memset(shu1,0,sizeof(shu1));17 memset(shu2,0,sizeof(shu2));18 len1=strlen(str1);19 len2=strlen(str2);20 //printf("lenstr1=%d,lenstr2=%d",len1,len2);//21 for(j=0,i=len1-1;i>=0;i--)22 shu1[j++]=str1[i]-'0';23 for(j=0,i=len2-1;i>=0;i--)24 shu2[j++]=str2[i]-'0';25 for(i=0;i =10)29 {30 shu1[i]%=10;31 shu1[i+1]++;32 }33 }34 //for(i=0;i =0;j--)37 if(shu1[j])break;38 if(j==-1)39 printf("0");40 else 41 {42 for(i=j;i>=0;i--)43 printf("%d",shu1[i]);44 }45 if(k