// Jan Zachar 03/12/22 // #include <iostream> #include <string> using namespace std; string a, b; string c; bool zero = true; void reverse_string(string &in) { for (int i = 0; i < in.length()/2; i++) { swap(in[i], in[in.length()-i-1]); } } int main() { ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> a >> b; reverse_string(a); reverse_string(b); c.resize(max(a.length(), b.length())+1, '0'); a.resize(c.length(), '0'); b.resize(c.length(), '0'); for (int i = 0; i < c.length(); i++) { c[i] += a[i]+b[i]-(48*2); if (c[i] >= 58) { c[i] -= 10; c[i+1] += 1; } } reverse_string(c); for (int i = 0; i < c.length(); i++) { if (c[i] == '0' && zero) continue; zero = false; cout << c[i]; } cout << endl; 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | // Jan Zachar 03/12/22 // #include <iostream> #include <string> using namespace std; string a, b; string c; bool zero = true; void reverse_string(string &in) { for (int i = 0; i < in.length()/2; i++) { swap(in[i], in[in.length()-i-1]); } } int main() { ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> a >> b; reverse_string(a); reverse_string(b); c.resize(max(a.length(), b.length())+1, '0'); a.resize(c.length(), '0'); b.resize(c.length(), '0'); for (int i = 0; i < c.length(); i++) { c[i] += a[i]+b[i]-(48*2); if (c[i] >= 58) { c[i] -= 10; c[i+1] += 1; } } reverse_string(c); for (int i = 0; i < c.length(); i++) { if (c[i] == '0' && zero) continue; zero = false; cout << c[i]; } cout << endl; return 0; } |