Advertisement
Saleh127

CF 770B

Oct 8th, 2020
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll sum(ll x)
  6. {
  7. ll ans=0;
  8. while(x)
  9. {
  10. ans+=(x%10);
  11. x/=10;
  12. }
  13. return ans;
  14. }
  15.  
  16. int main()
  17. {
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0);cout.tie(0);
  20.  
  21. ll a,c=1,d,e,i,j,k,ans;
  22.  
  23. cin>>a;
  24. ans=a;
  25. for(i=1;i<=18;i++)
  26. {
  27. c*=10;
  28. k=(a/c)*c-1;
  29. if(sum(k)>sum(ans) || (sum(k)==sum(ans) && k>ans))
  30. {
  31. ans=k;
  32. }
  33. }
  34. cout<<ans<<endl;
  35. return 0;
  36. }
  37.  
Advertisement
RAW Paste Data Copied
Advertisement