文章
79
粉丝
221
获赞
46
访问
198.3k
#include <iostream>
#include <string>
using namespace std;
string SP(string s1, string s2) {
int i = s1.size() - 1, j = s2.size() - 1;
int k = 0;
string res = "";
while (i >= 0 && j >= 0) {
res = char((s1[i] - '0' + s2[j] - '0' + k) % 10 + '0') + res;
k = (s1[i] - '0' + s2[j] - '0' + k) / 10;
i--, j--;
}
while (i >= 0) {
res = char((s1[i] - '0' + k) % 10 + '0') + res;
k = (s1[i] - '0' + k) / 10;
i--;
}
while (j >= 0) {
res = char((s2[j] - '0' + k) % 10 + '0') + res;
k = (s2[j] - '0' + k) / 10;
j--;
}
if (k)
res = char(k + '0') + res;
return res;
}
int main() {
string s1,s2;
while(cin>>s1>>s2)
cout<<SP(s1,s2)<<endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发