#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string a, b; char w[5007]; cin >> a >> b; while(a.size() < b.size()){ a ='0'+a; } while(a.size() > b.size()){ b ='0'+b; } int x, r=0; for(int i=b.size()-1; i>=0; --i){ x = (a[i]-'0') + (b[i]-'0'); x+=r; r = x/10; x%=10; w[i] = (x+'0'); } if(r!=0) cout << r; for(int i=0; i<b.size(); ++i) cout << w[i]; 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 24 25 26 27 | #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string a, b; char w[5007]; cin >> a >> b; while(a.size() < b.size()){ a ='0'+a; } while(a.size() > b.size()){ b ='0'+b; } int x, r=0; for(int i=b.size()-1; i>=0; --i){ x = (a[i]-'0') + (b[i]-'0'); x+=r; r = x/10; x%=10; w[i] = (x+'0'); } if(r!=0) cout << r; for(int i=0; i<b.size(); ++i) cout << w[i]; return 0; } |