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
#include <iostream>
#include <stack>
using namespace std;
const int stala=5010;
char tab[stala];
char tab2[stala];
stack<int>stos;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a,a2;
    cin>>a>>a2;
    int dl=(int)a.length();
    int dl2=(int)a2.length();
    int maks=max(dl,dl2);
    int index=dl-1;
    for(int i=1;i<=maks;i++){
        tab[i]='0';
        tab2[i]='0';
    }
    for(int i=maks;i>=maks-dl+1;i--){
        tab[i]=a[index];
        index--;
    }
    index=dl2-1;
    for(int i=maks;i>=maks-dl2+1;i--){
        tab2[i]=a2[index];
        index--;
    }
    int ile_dodac=0;
    for(int i=maks;i>=1;i--){
        int x=tab[i]-'0';
        int x2=tab2[i]-'0';
        int suma=x+x2+ile_dodac;
        ile_dodac=suma/10;
        stos.push(suma%10);
    }
    if(ile_dodac>0){
        stos.push(ile_dodac);
    }
    while(!stos.empty()){
        cout<<stos.top();
        stos.pop();
    }

    return 0;
}