题意:大数加法。
思路:简单模拟。
class Solution {
public:
string addStrings(string num1, string num2) {
string re;
int c = 0;
std::reverse(num1.begin(), num1.end());
std::reverse(num2.begin(), num2.end());
int i = 0;
while(i < num1.length() ||i < num2.length()) {
int a = 0;
int b = 0;
if(i < num1.length()) a = num1[i] - '0';
if(i < num2.length()) b = num2[i] - '0';
re += (a + b + c) % 10 + '0';
c = (a + b + c) / 10;
i ++;
}
if(c) re += c + '0';
std::reverse(re.begin(), re.end());
return re;
}
};