题号:1601
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include<iostream> #include<string> using namespace std; void reverse(string & s){ for(int i=0;i<s.size()/2;i++){ swap(s[i],s[s.size()-1-i]); } } int main(){ string s1,s2; cin>>s1>>s2; if(s1.length()>s2.length()){ swap(s1,s2); } reverse(s1); reverse(s2); int s1len=s1.length(),s2len=s2.length(); for(int i=0;i<s1len;i++){ s2[i]+=s1[i]-'0'; } for(int i=0;i<s2len-1;i++){ if(s2[i]>'9'){ s2[i+1]+=(s2[i]-'0')/10; s2[i]='0'+(s2[i]-'0')%10; } } if(s2[s2len-1]>'9'){ s2.append(1,'0'+(s2[s2len-1]-'0')/10); s2[s2len-1]='0'+(s2[s2len-1]-'0')%10; } reverse(s2); cout<<s2; } |