CF2203B.Beautiful Numbers
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's define F(x) as the sum of the digits of x. An integer x is considered beautiful if F(F(x))=F(x).
You are given an integer x. In one move, you can choose any digit in the number and replace it with another. The resulting number cannot have leading zeros.
Your task is to calculate the minimum number of moves (possibly zero) required to make the given number beautiful.
我们定义 F(x) 为 x 的各位数字之和。若一个整数 x 满足 F(F(x))=F(x),则称其为“美丽的”。
给定一个整数 x。在一次操作中,你可以选择该数中的任意一位数字,并将其替换为另一个数字。所得的新数不能有前导零。
你的任务是计算使给定数字变为“美丽”的最小操作次数(可以为零)。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The only line of each test case contains a single integer x (1≤x≤1018).
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例仅有一行,包含一个整数 x(1≤x≤1018)。
输出格式
For each test case, print a single integer — the minimum number of moves (possibly zero) required to make the given number beautiful.
对于每个测试用例,输出一个整数——使给定数字变为“美丽数字”所需的最少移动次数(可能为零)。
输入输出样例
输入#1
4 1 37 645 2374236843276813
输出#1
0 1 2 12
说明/提示
In the first example, the given number is already beautiful.
In the second example, in one move, we can get the beautiful number 33 (the changed digit is underlined).
In the third example, in two moves, we can get the beautiful number 140 (the changed digits are underlined).
在第一个例子中,给定的数字本身已经是优美的。
在第二个例子中,通过一次操作,我们可以得到优美数字 33(被修改的数字用下划线标出)。
在第三个例子中,通过两次操作,我们可以得到优美数字 140(被修改的数字用下划线标出)。
输入解题思路,AI测评打分。不知道怎么写?