#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string a, b; cin >> a >> b; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); if(a.size() < b.size()) swap(a, b); while(a.size() != b.size()) b += '0'; int p = 0; vector<int> w; int c; for(int i = 0; i < a.size(); i++){ c = a[i] + b[i] - 96 + p; p = c/10; w.push_back(c%10); } if(p) cout << p; for(int i = a.size()-1; i >= 0; 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 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string a, b; cin >> a >> b; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); if(a.size() < b.size()) swap(a, b); while(a.size() != b.size()) b += '0'; int p = 0; vector<int> w; int c; for(int i = 0; i < a.size(); i++){ c = a[i] + b[i] - 96 + p; p = c/10; w.push_back(c%10); } if(p) cout << p; for(int i = a.size()-1; i >= 0; i--) cout << w[i]; return 0; } |