欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1857B.Maximum Rounding
Maximum Rounding
Given a natural number . You can perform the following operation:
- choose a positive integer and round to the -th digit
Note that the positions are numbered from right to left, starting from zero. If the number has digits, it is considered that the digit at the -th position is equal to .
The rounding is done as follows:
- if the digit at the -th position is greater than or equal to , then the digit at the -th position is increased by , otherwise the digit at the -th position remains unchanged (mathematical rounding is used).
- if before the operations the digit at the -th position was , and it should be increased by , then we search for the least position (), where the digit at the -th position is less than and add to the digit at the -th position. Then we assign .
- after that, all digits which positions are less than are replaced with zeros.
Your task is to make as large as possible, if you can perform the operation as many times as you want.
For example, if is equal to , then if you choose consecutively:
- , then after the operation will become
- , then after the operation will become
- , then after the operation will become
- , then after the operation will become
To maximize the answer, you need to choose first, and then , then the number will become .
Input
The first line contains a single integer () — the number of test cases.
Each test case consists of positive integer with a length of up to . It is guaranteed that there are no leading zeros in the integer.
It is guaranteed that the sum of the lengths of all integers over all test cases does not exceed .
Output
For each set of input data, output the maximum possible value of after the operations. The number should not have leading zeros in its representation.
Note
In the first sample, it is better not to perform any operations.
In the second sample, you can perform one operation and obtain .
In the third sample, you can choose or . In both cases the answer will be .
Samples
10
1
5
99
913
1980
20444
20445
60947
419860
40862016542130810467
1
10
100
1000
2000
20444
21000
100000
420000
41000000000000000000
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |