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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
constexpr int maxN=5000+7;
string a;
string b;
int c[maxN]={0};
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>a>>b;
    int i=a.size()-1;
    int j=b.size()-1;
    int k=maxN-1;
    bool more=false;
 
    while (i>=0&&j>=0)
    {
        int x=a[i]-48;
        int y=b[j]-48;
        c[k]=x+y;
        if(more){
            c[k]++;
        }
        if(c[k]>9){
            c[k]=c[k]%10;
            more=true;
        }else{
            more=false;
        }
        i--;j--;k--;
    }
    while (i>=0)
    {
        c[k]=a[i]-48;
        if(more){
            c[k]++;
        }
        if(c[k]>9){
            c[k]=c[k]%10;
            more=true;
        }else{
            more=false;
        }
        i--;k--;
    }
    while (j>=0)
    {
        c[k]=b[j]-48;
        if(more){
            c[k]++;
        }
        if(c[k]>9){
            c[k]=c[k]%10;
            more=true;
        }else{
            more=false;
        }
        j--;k--;
    }
    if(more){
        c[k]=1;
        k--;
    }
    for (int i = k+1; i < maxN; i++)
    {
        cout<<c[i];
    }
    return 0;
}