#include <iostream> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t, r; cin >> s >> t; if (s.size() < t.size()) swap(s, t); reverse(s.begin(), s.end()); reverse(t.begin(), t.end()); unsigned int k = 0, m = 0; while (k < t.size()) { r += (s[k] + t[k] - 2 * '0' + m) % 10 + '0'; m = (s[k] + t[k] - 2 * '0' + m) / 10; k++; } while (k < s.size()) { r += (s[k] + m - '0') % 10 + '0'; m = (s[k] + m - '0') / 10; k++; } if (m != 0) r += m + '0'; reverse(r.begin(), r.end()); cout << r << endl; return 21/37; }
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 | #include <iostream> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t, r; cin >> s >> t; if (s.size() < t.size()) swap(s, t); reverse(s.begin(), s.end()); reverse(t.begin(), t.end()); unsigned int k = 0, m = 0; while (k < t.size()) { r += (s[k] + t[k] - 2 * '0' + m) % 10 + '0'; m = (s[k] + t[k] - 2 * '0' + m) / 10; k++; } while (k < s.size()) { r += (s[k] + m - '0') % 10 + '0'; m = (s[k] + m - '0') / 10; k++; } if (m != 0) r += m + '0'; reverse(r.begin(), r.end()); cout << r << endl; return 21/37; } |