P10101: 数字魔法
传统题
2.000s
时间限制
256MB
内存限制
6 提交
3 解决
【题目描述】
【题目描述】
在看完最后一部哈利波特电影后,小杰拉尔德也决定练习魔法。他在父亲的魔法书里发现了一个咒语,可以将任何数字相加
。就在杰拉尔德知道这一点的那一刻,他遇到了一个数字n。杰拉尔德可以对它施多少次咒语,直到这个数字变成一位数?
【输入】
第一行包含唯一的整数n(0≤n≤10100000)。它保证n不包含任何前导零。
【输出】
输出一个数字可以被其数字之和替换的次数,直到它只包含一个数字。
【输入】
0
【输出】
0
【输入】
10
【输出】
1
【输入】
991
【输出】
3
【说明】
在第一个例子中,数字已经是一位数-先驱不能施法。
第二个测试包含数字10。施放一次法术后,它就变成了1,这个过程就完成了。因此,杰拉德只能施一次咒语。
第三个测试包含编号991。当一个人施咒时,会发生以下变化:991→19→10→1。经过三次变换,这个数字变成了一位数。
【提示】
Output
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Note
In the first sample the number already is one-digit − Herald can't cast a spell.
The second test contains number
10. After one casting of a spell it becomes
1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number
991. As one casts a spell the following transformations take place:
991→19→10→1. After three transformations the number becomes one-digit