Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int rec(int number) {
- if(number == 0) {
- return 0;
- }
- int last_digit = number % 10;
- if(last_digit == 9) {
- last_digit = 7;
- }
- return rec(number / 10) * 10 + last_digit;
- }
- int main()
- {
- int number;
- cin >> number;
- cout << rec(number) << endl;
- return 0;
- }
- // rec(9592) = rec(959) * 10 + 2 = 757 * 10 + 2 = 7572
- // rec(959) = rec(95) * 10 + 7 = 75 * 10 + 7 = 757
- // rec(95) = rec(9) * 10 + 5 = 7 * 10 + 5 = 75
- // rec(9) = rec(0) * 10 + 7 = 0 * 10 + 7 = 7
- // rec(0) = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement