#include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <iomanip> #include <set> #include <list> #include <queue> #include <map> #include <vector> #include <stack> constexpr int N = 2007; std::vector<char> wyp; std::string l1, l2; void dod() { int pom = 0; for (int i = l1.size() - 1; i >= 0; --i) { int ok = ((l1[i] + l2[i] + pom) - (2 * '0')); wyp.push_back(ok % 10); pom = ok / 10; } if (pom == 1) { wyp.push_back(1); } } int main() noexcept { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cin >> l1 >> l2; if (l1.size() > l2.size()) { std::swap(l1, l2); } int x = l2.size() - l1.size(); for (int i = 0; i < x; ++i) { l1.insert(l1.begin(), '0'); } dod(); for (int i = wyp.size() - 1; i >= 0; --i) { std::cout << int(wyp[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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <iomanip> #include <set> #include <list> #include <queue> #include <map> #include <vector> #include <stack> constexpr int N = 2007; std::vector<char> wyp; std::string l1, l2; void dod() { int pom = 0; for (int i = l1.size() - 1; i >= 0; --i) { int ok = ((l1[i] + l2[i] + pom) - (2 * '0')); wyp.push_back(ok % 10); pom = ok / 10; } if (pom == 1) { wyp.push_back(1); } } int main() noexcept { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cin >> l1 >> l2; if (l1.size() > l2.size()) { std::swap(l1, l2); } int x = l2.size() - l1.size(); for (int i = 0; i < x; ++i) { l1.insert(l1.begin(), '0'); } dod(); for (int i = wyp.size() - 1; i >= 0; --i) { std::cout << int(wyp[i]); } } |