Advertisement
askarulytarlan

Untitled

Mar 11th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long n, mx = 0, num, j = 0;
  4.  
  5. long check(long long n){
  6. long long s = 0;
  7. while (n > 0){
  8. s = s + n % 10;
  9. n = n / 10;
  10. }
  11. return s;
  12. }
  13. int main(){
  14. // freopen("C.in","r",stdin);
  15. // freopen("C.out","w",stdout);
  16. ios_base::sync_with_stdio(0);
  17. cin >> n;
  18. long long q = n;
  19. for(; q > 0; j++){
  20. q /= 10;
  21. }
  22. for(long long i = j*10-1; i <= n; i++){
  23. if(check(i) >= mx){
  24. mx = check(i);
  25. num = i;
  26. }
  27. }
  28. cout << num;
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement