hdu 1002 A + B Problem II

hdu 1002 A + B Problem II
InputThe first line of the input contains an integer T(1
蓝天幻想 1年前 已收到1个回答 举报

扶摇至上九万里 幼苗

共回答了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
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 2.072 s. - webmaster@yulucn.com