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
#include <cstdio>
#include <cstring>

const int max_n = 10000;

int na, nb;
char a[max_n + 1], b[max_n + 1], c[max_n + 1];

int main () {
  a[max_n] = b[max_n] = c[max_n] = 0;
  for (int i = 0; i < max_n; ++i) a[i] = b[i] = '0';
  scanf(" %s %s ", a, b);
  na = strlen(a);
  nb = strlen(b);
  int res = 0;
  for (int i = max_n; i > 0; --i) {
    int val_a = na - max_n + i - 1 >= 0 ? a[na - max_n + i - 1] - '0' : 0;
    int val_b = nb - max_n + i - 1 >= 0 ? b[nb - max_n + i - 1] - '0' : 0;
    c[i - 1] = '0' + (val_a + val_b + res) % 10;
    res = (val_a + val_b + res) / 10;
  }
  int start = 0;
  while (start < max_n - 1 && c[start] == '0') ++start;
  printf("%s\n", c + start);
}