304004: CF770B. Maximize Sum of Digits

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Maximize Sum of Digits

题意翻译

简述:给定一个整数x,你需要找到一个不超过x的a,使得它的各位数和在不超过x的整数中最大 输入格式: 输入只有一行,一个x(1<=x<=1e18) 输出格式: 输出只有一行,一个不超过x并且是范围内各位数之和最大的a (有多个各位数和相等的a请输出最大的a)。

题目描述

Anton has the integer $ x $ . He is interested what positive integer, which doesn't exceed $ x $ , has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.

输入输出格式

输入格式


The first line contains the positive integer $ x $ ( $ 1<=x<=10^{18} $ ) — the integer which Anton has.

输出格式


Print the positive integer which doesn't exceed $ x $ and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.

输入输出样例

输入样例 #1

100

输出样例 #1

99

输入样例 #2

48

输出样例 #2

48

输入样例 #3

521

输出样例 #3

499

Input

题意翻译

简述:给定一个整数x,你需要找到一个不超过x的a,使得它的各位数和在不超过x的整数中最大 输入格式: 输入只有一行,一个x(1<=x<=1e18) 输出格式: 输出只有一行,一个不超过x并且是范围内各位数之和最大的a (有多个各位数和相等的a请输出最大的a)。

加入题单

算法标签: