#include <algorithm> #include <cassert> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <ranges> #include <set> #include <string> #include <vector> using namespace std; #define all(x) (x).begin(), (x).end() string solve() { string x, y; cin >> x >> y; reverse(all(x)); reverse(all(y)); while (x.size() < y.size()) x += '0'; while (y.size() < x.size()) y += '0'; assert(x.size() == y.size()); int c = 0; for (int i = 0; i < x.size(); i++) { int d = (x[i] - '0') + (y[i] - '0') + c; x[i] = char(d % 10); c = d / 10; } if (c) x += char(c); reverse(all(x)); for (auto &d : x) d += '0'; return x; } #undef int int main() { ios::sync_with_stdio(false); cin.exceptions(cin.failbit); cin.tie(0); cout << solve() << endl; }
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <algorithm> #include <cassert> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <ranges> #include <set> #include <string> #include <vector> using namespace std; #define all(x) (x).begin(), (x).end() string solve() { string x, y; cin >> x >> y; reverse(all(x)); reverse(all(y)); while (x.size() < y.size()) x += '0'; while (y.size() < x.size()) y += '0'; assert(x.size() == y.size()); int c = 0; for (int i = 0; i < x.size(); i++) { int d = (x[i] - '0') + (y[i] - '0') + c; x[i] = char(d % 10); c = d / 10; } if (c) x += char(c); reverse(all(x)); for (auto &d : x) d += '0'; return x; } #undef int int main() { ios::sync_with_stdio(false); cin.exceptions(cin.failbit); cin.tie(0); cout << solve() << endl; } |