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
| #include <stdio.h> #include <string.h>
int a[1000005], b[1000005], ans[1000005]; char s[1000005], t[1000005];
int max(int a, int b) { return a > b ? a : b; }
int main() { scanf("%s", s); scanf("%s", t); int len1 = strlen(s), len2 = strlen(t); for (int i = len1 - 1, j = 0; i >= 0; i--, j++) { a[j] = s[i] - '0'; } for (int i = len2 - 1, j = 0; i >= 0; i--, j++) { b[j] = t[i] - '0'; } int len = max(len1, len2) + 1; for (int i = 0; i < len; i++) { ans[i] += a[i] + b[i]; ans[i + 1] += ans[i] / 10; ans[i] %= 10; } while (ans[len] == 0) len--; for (int i = len; i >= 0; i--) printf("%d", ans[i]); }
|