今天想起了这题,然后做了一遍
程序代码:
#include <stdio.h> #include <string.h> #define N 1000 + 10 int main() { int a[N] = {0}, b[N] = {0}, i, j, len, len1, len2, n, t; char s1[N], s2[N]; scanf("%d", &n); for(t = 1; t <= n; t++) { if(t > 1) printf("\n"); scanf("%s%s", s1, s2); len1 = strlen(s1); len2 = strlen(s2); for(i = len1 - 1, j = 0; i >= 0; i--) a[j++] = s1[i] - '0'; for(i = len2 - 1, j = 0; i >= 0; i--) b[j++] = s2[i] - '0'; len = len1 > len2 ? len1 : len2; for(i = 0; i < len; i++) { a[i] += b[i]; if(a[i] >= 10) { a[i] %= 10; a[i+1]++; } } printf("Case %d:\n", t); if(a[len]) printf("%d", a[len]); printf("%s + %s = ", s1, s2); for(i = len - 1; i >= 0; i--) printf("%d", a[i]); printf("\n"); } return 0; }为撒老是WA?,看了半天没看出来....大家帮忙看看吧......
仰望星空...........不忘初心!