#include <iostream>
#include <string>
#include <fstream>
using namespace std;
string big_num_plus(string a, string b)
{
if (b.size() > a.size())
{
string t;
t = b;
b = a;
a = t;
}
int a_len = a.size(),b_len=b.size();
int carry = 0;
int na, nb,sum;
while (a_len > 0)
{
na = a[a_len - 1] - 48;
if (b_len > 0)nb = b[b_len] - 48;
else nb = 0;
sum = na + nb + carry;
if (sum >= 10)
{
a[a_len - 1] = sum % 10 + '0';
carry = 1;
}
else
{
a[a_len-1] = sum + '0';
carry = 0;
}
a_len--;
b_len--;
}
if (carry == 1)
a = '1' + a;
return a;
}
int main()
{
string x = "111";
string y = "9";
string sum = big_num_plus(x, y);
cout << sum << endl;
system("pause");
}
转载于:https://my.oschina.net/u/3772904/blog/1803132