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
#include <bits/stdc++.h>
using namespace std;

int main() {
    string a, b; cin>>a>>b;
    if (a.size()>b.size()) swap(a, b);
    if (a == "0") {
        cout<<b;
        return 0;
    }   
    string res = "";
    int p = 0, r = 0, c = 0, d = 0; 
    int asz = a.size();
    for (int i=b.size(); i>asz; --i) {
        a = '0'+a;
    }
    for (int i=a.size()-1; i>=0; --i) {
        c = a[i]-'0';
        d = b[i]-'0';
        r = (c+d+p)%10;
        char x = r+'0';
        res = x + res;
        p = (c+d+p)/10;
    }
    if (p==1) res = '1'+res;
    cout<<res;
}