#include<bits/stdc++.h> using namespace std; int main(){ string a,b; cin>>a>>b; if(a.length()>b.length()){swap(a,b);} while(a.length()<b.length()){ a = '0'+a; } int n=a.length(),c=0; string ans=""; for(int i = n-1;i>=0;--i){ ans = char('0'+(a[i]+b[i]+c-2*'0')%10)+ans; c = (a[i]+b[i]+c-2*'0')/10; } if(c)cout<<c; cout<<ans; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<bits/stdc++.h> using namespace std; int main(){ string a,b; cin>>a>>b; if(a.length()>b.length()){swap(a,b);} while(a.length()<b.length()){ a = '0'+a; } int n=a.length(),c=0; string ans=""; for(int i = n-1;i>=0;--i){ ans = char('0'+(a[i]+b[i]+c-2*'0')%10)+ans; c = (a[i]+b[i]+c-2*'0')/10; } if(c)cout<<c; cout<<ans; return 0; } |