From Hangzhou Electric ACM
A + B Problem II
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 252440 Accepted Submission (s): 48647
Problem Description
I have a very simple problem for you. Given 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 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.
Output
For the 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 Input
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
Code:
#include <iostream>using namespace STD;#define MAXSIZEvoidReverseCharN[]) {intLen =strlen(n)-1;intTemp for(inti =0; I <= Len/2; i++) {temp = N[i]; N[i] = n[len-i]; N[len-i] = temp; }}voidSumCharNum1[],CharNum2[],CharTemp[]) {intLen1 =strlen(NUM1)-1;intLen2 =strlen(num2)-1;intTemplen =0; for(; Len1 >=0&& Len2 >=0; --len1,--len2) {intsum = Num1[len1] + num2[len2] + Temp[templen]-3*' 0 '; Temp[templen] = sum%Ten+' 0 '; Temp[templen +1] = SUM/Ten+' 0 '; templen++; } while(Len1 >=0) {intsum = Num1[len1] + Temp[templen]-2*' 0 '; Temp[templen] = sum%Ten+' 0 '; Temp[templen +1] = SUM/Ten+' 0 '; ++templen; --len1; } while(Len2 >=0) {intsum = Num2[len2] + Temp[templen]-2*' 0 '; Temp[templen] = sum%Ten+' 0 '; Temp[templen +1] = SUM/Ten+' 0 '; ++templen; --len2; }if(Temp[templen] = =' 0 ') {Temp[templen] =' + '; }Else{Temp[templen +1] =' + '; } reverse (temp);}intMainvoid){intNCharNum1[maxsize] = {};CharNum2[maxsize] = {};CharNum3[maxsize] = {};Cin>> N; for(inti =0; I < n; i++) {memset(NUM3,' 0 ',sizeof(num3));Cin>> num1 >> num2;cout<<"Case"<< i +1<<":"<< Endl; Sum (NUM1, num2, num3);cout<< NUM1 <<" + "<< num2 <<" = "<< num3 << Endl;if(i +1< n) {cout<< Endl; }} System ("Pause");return 0;}
A + B Problem II