Advertisement
Josif_tepe

Untitled

Oct 17th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int rec(int number) {
  5.     if(number == 0) {
  6.         return 0;
  7.     }
  8.     int last_digit = number % 10;
  9.     if(last_digit == 9) {
  10.         last_digit = 7;
  11.     }
  12.     return rec(number / 10) * 10 + last_digit;
  13. }
  14. int main()
  15. {
  16.     int number;
  17.     cin >> number;
  18.     cout << rec(number) << endl;
  19.     return 0;
  20. }
  21. // rec(9592) = rec(959) * 10 + 2 = 757 * 10 + 2 = 7572
  22. // rec(959) = rec(95) * 10 + 7 = 75 * 10 + 7 = 757
  23. // rec(95) = rec(9) * 10 + 5 = 7 * 10 + 5 = 75
  24. // rec(9) = rec(0) * 10 + 7 = 0 * 10 + 7 = 7
  25. // rec(0) = 0
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement