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
30
31
32
33
34
35
36
37
38
39
40
#define make_pair mp
#define emplace_back pb
#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 5005;
char s[N], c[N];
int ans[N];
int main()
{
    scanf("%s", s);
    scanf("%s", c);
    if(s[0] == '0' && c[0] == '0') {
        printf("0\n");
        return 0;
    }
    int n = 0, m = 0;
    while(s[n]) n++;
    while(c[m]) m++;
    if(n <= m) {
        swap(n, m);
        swap(c, s);
    }
    s[n] = '0';
    for(int i=n;i>0;i--) swap(s[i], s[i-1]);
    for(int i=0;i<m;i++) c[n-i] = c[m-i-1];
    for(int i=n-m;i>=0;i--) c[i] = '0';
    //printf("%s\n%s\n", s, c);
    int pop = 0;
    for(int i=n;i>=0;i--) {
        int d1 = s[i] - '0', d2 = c[i] - '0';
        int d = d1 + d2 + pop;
        ans[i] = d % 10;
        pop = d / 10;
    }
    int i = 0;
    while(ans[i] == 0) i++;
    for(int j=i;j<=n;j++) printf("%d", ans[j]);
	return 0;
}