Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long long n, mx = 0, num, j = 0;
- long check(long long n){
- long long s = 0;
- while (n > 0){
- s = s + n % 10;
- n = n / 10;
- }
- return s;
- }
- int main(){
- // freopen("C.in","r",stdin);
- // freopen("C.out","w",stdout);
- ios_base::sync_with_stdio(0);
- cin >> n;
- long long q = n;
- for(; q > 0; j++){
- q /= 10;
- }
- for(long long i = j*10-1; i <= n; i++){
- if(check(i) >= mx){
- mx = check(i);
- num = i;
- }
- }
- cout << num;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement