hdu 1002 A + B Problem IIInputThe first line of the input contains an integer T(1

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/05 05:50:44
hdu 1002 A + B Problem IIInputThe first line of the input contains an integer T(1

hdu 1002 A + B Problem IIInputThe first line of the input contains an integer T(1
hdu 1002 A + B Problem II
InputThe first line of the input contains an integer T(1

hdu 1002 A + B Problem IIInputThe first line of the input contains an integer T(1
#include <stdio.h>
#include <string.h>
#define N 1500

int max(int d, int e) {
return d > e ? d : e;
}

int main() {
int max(int a, int b);
int i, j;
int n;
while (scanf("%d", &n) != EOF) {
char s1[N], s2[N];
int l1, l2, l;
int a[N] = { 0 }, b[N] = { 0 }, c[N] = { 0 };
for (i = 0; i < n; i++) {
scanf("%s", &s1);
scanf("%s", &s2);
l1 = strlen(s1);
l2 = strlen(s2);
l = max(l1, l2);
for (j = 0; j < l1; j++) {
a[j] = s1[l1 - 1 - j] - '0';
}
for (j = 0; j < l2; j++) {
b[j] = s2[l2 - 1 - j] - '0';
}
for (j = 0; j < l; j++) {
c[j] += a[j] + b[j];
if (c[j] >= 10) {
c[j + 1]++;
c[j] -= 10;
}
}
if (c[l] > 0) l++;
printf("Case %d:\n", i + 1);
printf("%s + %s = ", s1, s2);
for (j = 0; j < l; j++) {
printf("%d", c[l - j - 1]);
}
// 
printf("\n");
if (i != n - 1) {
printf("\n");
}
}
return 0;
}
}