题解 | #a+b#
a+b
http://www.nowcoder.com/practice/4c39c984ea3848b48e111b8e71ec1dd4
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string a, b, ans;
while (cin >> a >> b) {
ans = "";
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int len1 = a.size();
int len2 = b.size();
int i = 0,carry = 0;
while (i < len1 && i < len2) {
int cur = a[i] - '0' + b[i] - '0' + carry;
ans += to_string(cur % 10);
carry = cur / 10;
i++;
}
if (i < len2) {
swap(a, b);
swap(len1, len2);
}
while (i < len1) {
int cur = a[i] - '0' + carry;
ans += to_string(cur % 10);
carry = cur / 10;
i++;
}
if (carry)
ans += to_string(carry);
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
}