B.cpp 571 B

123456789101112131415161718192021222324
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. string a, b;
  5. cin >> a >> b;
  6. reverse(a.begin(), a.end());
  7. reverse(b.begin(), b.end());
  8. int n = max(a.size(), b.size());
  9. while (a.size() < n)a.push_back('0');
  10. while (b.size() < n)b.push_back('0');
  11. string c(n, '0');
  12. int sc = 0;
  13. for (int i = 0; i < n; i++) {
  14. int temp = sc + a[i] - '0' + b[i] - '0';
  15. sc = temp / 10;
  16. c[i] = '0' + temp % 10;
  17. }
  18. if (sc)c.push_back(sc + '0');
  19. reverse(c.begin(), c.end());
  20. cout << c << endl;
  21. return 0;
  22. }