Joao_Joao

Removing Digits - C++

Sep 26th, 2020 (edited)
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;typedef long double llf;typedef double fl;typedef string str;typedef pair<double, double> dd;
  5. typedef vector<int> vi;typedef vector<vector<int>> vvi;typedef vector<fl> vf;typedef vector<ll> vl;
  6. typedef vector<llf> vlf;typedef vector<char> vc;typedef vector<str> vs;typedef pair<int,int> ii;
  7. # define f(i,a,b,c) for(ll i=a;i<b;i+=c)
  8. # define fd(i,a,b,c) for(ll i=a;i>=b;i-=c)
  9. # define w(x) while(x--)
  10. # define ctoi(a) (a-'0')
  11. # define pb push_back
  12. # define eb emplace_back
  13. # define lb lower_bound
  14. # define ub upper_bound
  15. # define be(x) x.begin(), x.end()
  16. # define rbe(x) x.rbegin(), x.rend()
  17. # define _(x) ios::sync_with_stdio(0);cin.tie(0);cout.precision(x);cout.setf(ios::fixed);
  18.  
  19. int n, re=0;
  20. int ma(int x){
  21.     int mai, num;
  22.     str p = to_string(x);
  23.     mai=0;
  24.     for(char i:p)num = ctoi(i), mai = max(mai, num);
  25.     return mai;
  26. }
  27. int dp(int x){
  28.     if(x==0)return re;
  29.     ++re;
  30.     return dp(x - ma(x));
  31. }
  32. int main(){_(0)
  33.     cin>>n;
  34.     cout<<dp(n)<<'\n';
  35. return 0;}
RAW Paste Data Copied