【限量版红题】题解:P10985

· · 题解

思路

很简单,双层循环,每次减去上一次的各个数位和,本来想利用 Python 的字符串转数字方便性只用一个循环的,但是会 TLE,所以多了一层循环。

代码

65pts

a = input()
n = int(a)
cnt = 0
while n != 0:
    tmp = 0
    for i in a:
        tmp += int(i)
    n -=tmp
    a = str(n)
    cnt += 1
print(cnt)

AC

n = int(input())
cnt = 0
while n:
    tmp = n
    while tmp:
        n -= tmp%10
        tmp //= 10
    cnt += 1
print(cnt)

记录

65pts

AC