//Dawid Lebryk #include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> sum(string a, string b) { if (a.size() < b.size()) swap(a, b); int d = a.size() - b.size(); string s; for (int i = 0; i < d; i++) { s += '0'; } s += b; vector<int> w; int r = 0, l; for (int i = a.size() - 1; i >= 0; i--) { l = (a[i] + s[i] - 2 * '0') + r; w.push_back(l % 10); r = l / 10; } if (r == 1) w.push_back(r); return w; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string a, b; cin >> a >> b; vector<int> W = sum(a, b); for (int i = W.size() - 1; i >= 0; i--) { cout << W[i]; } }
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 | //Dawid Lebryk #include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> sum(string a, string b) { if (a.size() < b.size()) swap(a, b); int d = a.size() - b.size(); string s; for (int i = 0; i < d; i++) { s += '0'; } s += b; vector<int> w; int r = 0, l; for (int i = a.size() - 1; i >= 0; i--) { l = (a[i] + s[i] - 2 * '0') + r; w.push_back(l % 10); r = l / 10; } if (r == 1) w.push_back(r); return w; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string a, b; cin >> a >> b; vector<int> W = sum(a, b); for (int i = W.size() - 1; i >= 0; i--) { cout << W[i]; } } |