A + B Problem II
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 429408 Accepted Submission (s): 83462
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.
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 Input
2 1 2 112233445566778899 998877665544332211
Sample Output
1 : 1 2 3 2:112233445566778899 998877665544332211 1111111111111111110
Add large numbers and note the format
1#include <iostream>2#include <cstring>3#include <string>4 using namespacestd;5 stringBigadd (stringNUM1,stringnum2) {6 7 stringRes;8 if(num1.size () = =0) {9res =num2;Ten returnRes; One } A if(num2.size () = =0) { -res =NUM1; - returnRes; the } - -res =""; - intN1 = Num1.size ()-1, N2 = Num2.size ()-1; + intcarry =0; - while(N1 >=0|| N2 >=0) { + A intA = N1 >=0? num1[n1--]-'0':0; at intb = N2 >=0? num2[n2--]-'0':0; - - intT = carry + A +b; -Carry = t/Ten; -t = t%Ten; -res = to_string (t) +Res; in } - //Judging if there's a carry. to while(carry) { + intT = carry/Ten; -Carry%=Ten; theres = to_string (carry) +Res; *carry =T; $ }Panax Notoginseng returnRes; - } the + intMain () { A intsum=0, Count; theCin>>count; + if(count>=1&&count<= -) { - stringa[ A][2]; $ for(intI=0; i<count; i++) { $cin>>a[i][0]>>a[i][1]; - } - for(intI=0; i<count; i++) { thecout<<" Case"<<i+1<<":"<<Endl; -cout<<a[i][0]<<" + "<<a[i][1]<<" = "<<bigadd (a[i][0],a[i][1]) <<Endl;Wuyi if(i+1!=count) { thecout<<Endl; - } Wu } - } About return 0; $}
Avionics 1002 A + B problem II//algorithm