Advertisement
LEGEND2004

Removing Digits

Aug 24th, 2023
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. int f(int n){
  7.     if(!n)
  8.         return 0;
  9.     int m = 0;
  10.     int x = n;
  11.     while(n){
  12.         m = max(m , n % 10);
  13.         n /= 10;
  14.     }
  15.     return 1 + f(x - m);
  16. }
  17.  
  18. signed main()
  19. {
  20.     int n;
  21.     cin >> n;
  22.     cout << f(n) << endl;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement