A - A + B Problem II
I have a very simple problem for you. Given two 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 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. OutputFor 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
21 2112233445566778899 998877665544332211
Sample Output
Case 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110 这道题一开始的思路是直接用字符数组去处理,做到一半发现实在太麻烦了,百度到他们把他放在整形数组里去处理好理解且方便. 且此题有BUG,我的程序输入1 9和1 99999999999这类数时候答案总是0,但是依然AC了- -!(玄学改变命运),不过最后还是改了一下,使程序更完美, 把进位的变量进行判断TM=1输出TM,else continue; 下面是我的程序:
1 #include2 using namespace std; 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 int max(int a,int b)11 {12 return a>b?a:b;13 }14 int main()15 {16 char a1[1010],b1[1010];17 int a[1010],b[1010],c[1010];18 int t,i,j;19 cin>>t;20 for(int k=1;k<=t;k++)21 {22 memset(a1,0,sizeof(a1));23 memset(b1,0,sizeof(b1));24 memset(a,0,sizeof(a));25 memset(b,0,sizeof(b));26 memset(c,0,sizeof(c));27 cin>>a1>>b1;28 int lena,lenb;29 lena=strlen(a1);30 lenb=strlen(b1);31 for(i=0,j=lena-1;i =lenb)41 {42 for(i=0;i