CF770B.Maximize Sum of Digits

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

安东有一个整数 xx。他感兴趣的是:不超过 xx 的正整数中,哪个数的各位数字之和最大?

你的任务是帮助安东找出这个数。如果有多个这样的数,则取其中最大的那个。

输入格式

The first line contains the positive integer x (1 ≤ x ≤ 1018) — the integer which Anton has.

第一行包含正整数 xx(1≤x≤10181 \le x \le 10^{18})——安东所拥有的整数。

输出格式

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.

输出不超过 xx 的正整数中各位数字之和最大的那个数。如果存在多个这样的整数,则输出其中最大的一个。输出的整数不能包含前导零。

输入输出样例

  • 输入#1

    100

    输出#1

    99
  • 输入#2

    48

    输出#2

    48
  • 输入#3

    521

    输出#3

    499

输入解题思路,AI测评打分。不知道怎么写?

首页