A + B Problem II
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 265243 Accepted Submission (s): 51347
Problem Descriptioni has a very simple problem for you. Given integers A and B, your job is to calculate the Sum of A + B.
Inputthe 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 both positive integers, A and B. Notice that the integers is very large, that M EANs should not process them by using 32-bit integer. Assume the length of each integer would not exceed 1000.
Outputfor Each test case, you should output of the lines. The first line was "Case #:", # means the number of the the test case. The second line is the equation "A + b = sum", sum means the result of A + B. Note there is some spaces int the Equati On. Output a blank line between the test cases.
Sample Input2 1 2 112233445566778899 998877665544332211
Sample outputcase 1:1 + 2 = 3 Case 2:1.,122,334,455,667,79e,+17 + 998877665544332211 = 1111111111111111110
Authorignatius.l
Recommendwe carefully selected several similar problems for you:1005 1020 1715 1040 1753
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespacestd;intMain () {Chara[1005]; Charb[1005]; intsum[1005]; intT,lena,lenb; scanf ("%d",&t); intcout=0; while(t--) {cout++; scanf ("%s", a); scanf ("%s", B); Lena=strlen (a); LenB=strlen (b); memset (SUM,0,sizeof(sum)); inti,j,k,l,f; for(i=lena-1, j=lenb-1, k=0; i>=0&&j>=0; I--, j--) {sum[k+1]= (sum[k]+a[i]-'0'+b[j]-'0')/Ten; SUM[K]= (sum[k]+a[i]-'0'+b[j]-'0')%Ten; K++; if(i==0&&j!=0) { for(l=j-1; l>=0; l--) {sum[k+1]= (sum[k]+b[l]-'0')/Ten; SUM[K]= (sum[k]+b[l]-'0')%Ten; K++; } } Else if(i!=0&&j==0) { for(l=i-1; l>=0; l--) {sum[k+1]= (sum[k]+a[l]-'0')/Ten; SUM[K]= (sum[k]+a[l]-'0')%Ten; K++; } } } if(sum[k]!=0)//must be placed outside the loop
K++; printf ("Case %d:\n", cout); printf ("%s +%s =", A, b); for(f=k-1; f>=0; f--) {{printf ("%d", sum[f]); }} printf ("\ n"); if(t!=0) printf ("\ n"); }}
HDU1002 A + B problem II