fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string Sum(string n , string m) {
  5. string num = m;
  6. // make the length of num and n in the same size
  7. while (n.length() < num.length()) {
  8. n = "0" + n;
  9. }
  10. while (n.length() > num.length()) {
  11. num = "0" + num;
  12. }
  13. int curry = 0;
  14. string result = "";
  15. for (int i = n.length() - 1; i >= 0; i--) {
  16. int x = (n[i] - '0') + (num[i] - '0') + curry;
  17. char a = (x%10)+'0';
  18. result = a + result;
  19. curry = x / 10;
  20. }
  21. if (curry != 0){
  22. char a = curry+'0';
  23. result = a + result;
  24. }
  25. return result;
  26. }
  27. string multi(string n ){
  28. string result = "";
  29. int curry = 0;
  30. for(int i = n.length()-1 ; i>=0 ; i--){
  31. int x = ((n[i]-'0')*9) + curry;
  32. char a = (x%10)+'0';
  33. result = a + result;
  34. curry = x/10;
  35. }
  36. if(curry != 0){
  37. char a = curry + '0';
  38. result = a + result;
  39. }
  40. int t = 3;
  41. string k = result;
  42. while(t--){
  43. string secondNum = k+"0";
  44. k = Sum(result , secondNum);
  45. //cout << secondNum << " " << k << endl;
  46. }
  47. return k;
  48. }
  49. int main() {
  50. string n , a = "9999";
  51. cin >> n;
  52. cout << Sum(n,a) << endl << multi(n);
  53. }
  54.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
9999
000