fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main(void)
  7. {
  8. string a, b;
  9.  
  10. cin >> a >> b;
  11. string result(max(a.length(), b.length()), '0');
  12. int key = 0;
  13.  
  14. for (int i = 0; i < result.length(); i++)
  15. {
  16. int sum = key;
  17. key = 0;
  18.  
  19. if (i < a.size())
  20. sum += a[a.length() - i - 1] - '0';
  21.  
  22. if (i < b.size())
  23. sum += b[b.length() - i - 1] - '0';
  24.  
  25. if (sum > 9)
  26. {
  27. key = 1;
  28. sum -= 10;
  29. }
  30.  
  31. result[result.length() - i - 1] = sum + '0';
  32. }
  33. if (key)
  34. cout << 1;
  35. cout << result;
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 4900KB
stdin
9223372036854775807 9223372036854775808
stdout
18446744073709551615