A + B Problem II

题目链接
Problem Description
I have a very simple problem for you. Given two 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 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.

Output
For 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
2
1 2
112233445566778899 998877665544332211

Sample Output
Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<cmath>
#include<cstdlib>
#define MAX 1005

using namespace std;

char a[MAX], b[MAX], ans[MAX], resa[MAX], resb[MAX];
int alen, blen, y;

void strrev(char *s, int len)
{
char c;
int mid = len >> 1;
for(int i=0; i<mid; i++)
{
c = s[i];
s[i] = s[len - 1 - i];
s[len - 1 - i] = c;
}
}

void strsum()
{
int y = 0;
for(int i=0; i<blen; i++)
{
y = y+ans[i]+b[i]-96;
ans[i] = y%10 + 48;
y/=10;
}
for(int i=blen; i<alen; i++)
{
y = y+ans[i]-48;
ans[i] = y % 10 + 48;
y/=10;
}
if(y)
{
printf("1");
}
for(int i=alen-1; i>-1; i--)
{
printf("%c", ans[i]);
}
printf("\n");
}

int main()
{
int tc;
scanf("%d", &tc);
for(int i=1; i<=tc; i++)
{
memset(ans, 0, sizeof(ans));
scanf("%s %s", &a, &b);
strcpy(resa, a);
strcpy(resb, b);
strrev(a, strlen(a));
strrev(b, strlen(b));
if(strlen(a)>strlen(b))
{
strcpy(ans, a);
}
else
{
strcpy(ans, b);
strcpy(b, a);
}
alen = strlen(ans);
blen = strlen(b);
printf("Case %d:\n%s + %s = ", i, resa, resb);
strsum();
if(i<tc)printf("\n");
}
return 0;
}