解题思路:
(1)设置进位
#include<iostream>
using namespace std;
string helper(string &s1,string &s2) {
int i=s1.length()-1,j=s2.length()-1;
int c=0;
string str="";
while(i>=0 && j>=0) {
int a = (s1[i]-'0')+(s2[j]-'0')+c;
if(a>=10) {
a-=10;
c=1;
} else c=0;
char c = a+'0';
str = c+str;
i--;
j--;
}
while(i>=0) {
int a = (s1[i]-'0')+c;
if(a>=10) {
a-=10;
c=1;
} else c=0;
char c = a+'0';
str = c+str;
i--;
}
while(j>=0) {
int a = (s2[j]-'0')+c;
if(a>=10) {
a-=10;
c=1;
} else c=0;
char c = a+'0';
str = c+str;
j--;
}
if(c==1) return '1'+str;
else return str;
}
int main() {
string s1,s2;
while(cin>>s1) {
cin>>s2;
cout<<helper(s1,s2)<<endl;
}
return 0;
}