c++大数
加法
string add(string a, string b) {
string s;
int l1 = a.size(), l2 = b.size();
int carry = 0;
int i, j;
for (i = l1 - 1, j = l2 - 1; i >= 0 && j >= 0; i--, j--) {
int tmp = a[i] - '0' + b[j] - '0' + carry;
s += tmp % 10 + '0';
carry = tmp / 10;
}
while (i >= 0) {
int tmp = a[i--] - '0' + carry;
s += tmp % 10 + '0';
carry = tmp / 10;
}
while (j >= 0) {
int tmp = b[j--] - '0' + carry;
s += tmp % 10 + '0';
carry = tmp / 10;
}
if (carry)
s += "1";
return s;
}