申请添加题解 carlxj · 2024-08-25 21:42:51 · 题解 题目 分析 题目大意: 求一个正整数,不断减去它的数位之和,直到为 0 的操作次数。 思路: 对正整数 n 进行以下操作:每一次设两个变量 ans 和 t , ans 表示数位之和。t 用来临时存储 n 的值。用 while 循环求出数位和后,拿 n 减去 ans ,同时计数器 +1 ,最终的答案就在计数器 s 中。 代码: a=int(input()) s=0 while a>0: t=a ans=0 while t>0: ans+=t%10 t//=10 a-=ans s+=1 print(s)