扶摇至上九万里
幼苗
共回答了21个问题采纳率:100% 举报
#include
#include
#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;
}
}
1年前
10