fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define str string
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8.  
  9. const ll limit = 1e5 + 5;
  10. const ll mod = 1e9 + 7;
  11.  
  12. str sum(str a, str b){
  13. while(a.length() < b.length()) a = '0' + a;
  14. while(a.length() > b.length()) b = '0' + b;
  15.  
  16. str ans = "";
  17. int cur = 0, tmp = 0;
  18. for(int i = a.length() - 1; i >= 0; i--){
  19. tmp = a[i] - '0' + b[i] - '0' + cur;
  20. if(tmp >= 10){
  21. tmp -= 10;
  22. cur = 1;
  23. }
  24. ans = ans + char(tmp + '0');
  25. }
  26. if(cur > 0) ans = '1' + ans;
  27. return ans;
  28. }
  29.  
  30. int main() {
  31. ios_base::sync_with_stdio(0);
  32. cin.tie(0); cout.tie(0);
  33.  
  34. str a, b, c;
  35. cin >> a >> b >> c;
  36. cout << sum(sum(a, b), c);
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty