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
#include <stdio.h>
#include <string> 
int main()
{
    char tab[5002];
    scanf("%s", tab);
    std::string a = tab;
    scanf("%s", tab);
    std::string b =tab;
    if(b.size() > a.size())
	std::swap(a,b);
    int add =0 ;
    int diff = a.size() - b.size();
    for(int i =b.size()-1;i>=0;i--)
    {
	int sum = a[diff + i]-'0' + b[i] - '0' + add;
	a[diff+i] = sum%10 + '0';
	add = sum/10;
    }
    for(int i = diff-1; i>=0; i--)
    {
	int sum = a[i]-'0' + add;
	a[i] = (sum%10) + '0';
	add= sum/10;
    }
    if(add > 0 )
	a = "1" + a;
    printf("%s\n",a.c_str());
}