A + B Problem II
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 242959 Accepted Submission (s): 46863
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 Input21 2112233445566778899 998877665544332211Sample outputcase 1:1 + 2 = 3
Case 2:1.,122,334,455,667,79e,+17 + 998877665544332211 = 1111111111111111110
Pay attention to zeroing the array
#include <stdio.h> #include <stdlib.h> #include <string.h> int main () { int m,j,n,i,l1,l2,t,k=1; Char s1[1100]; Char s2[1100]; int s3[1100]; int s4[1100];scanf ("%d", &n), while (n--) {scanf ("%s%s", s1,s2); memset (s3,0,sizeof ( S3)); Clear the array 0 memset (s4,0,sizeof (S4)); L1=strlen (S1); L2=strlen (S2) t=0;for (j=l1-1,i=0;j>=0;j--, i++) s3[i]=s1[j]-' 0 '; Converts a string to a number for (j=l2-1,i=0;j>=0;i++,j--) s4[i]=s2[j]-' 0 ', for (i=0;i<1100;i++) {s3[i]+=s4[i];if (s3[i]>=10) //Sum to you {s3[i]-=10;s3[i+1]++;}} printf ("Case%d:\n", k++);p rintf ("%s +%s =", s1,s2), and for (i=1099;i>=0;i--) if (s3[i]!=0) break;for (; i>=0;i--) printf ("%d", S3[i]);p rintf ("\ n"), if (n>0) printf ("\ n");} return 0;}
Hdoj 1002 A + B problem II