看到标题,我就想用Python写了,然而:
(下面的Python代码首先定义了一个 函数,用于计算一个整数的各位数字之和。然后定义了一个 函数,返回这个数变回零所需的分钟数。最后,通过输入一个正整数并调用函数,我们可以得到结果)
Code1(60pts,原始写法数位和+函数统计):
def digit(n):
s=0
while n>0:
k=n%10
s+=k
n=n//10
return s
def min(n):
m=0
while n>0:
n-=digit(n)
m+=1
return m
n=int(input())
print(min(n))Code2(60pts,换了个字符串写法+函数统计):
def digit(n):
str_n=str(n)
s=0
for c in str_n:
s+=int(c)
return s
def min(n):
m=0
while n>0:
n-=digit(n)
m+=1
return m
n=int(input())
print(min(n))然后就把我逼疯了,却发现只是个 题
最后的最后,还是用上了万能的C++
Code3(100pts,正常):
#include<bits/stdc++.h>//万能头文件,不解释
using namespace std;
int n,cnt=0;
int f(){
int x=n,s=0;
while(x>0){
s+=x%10;//加上末位
x/=10;
}
return s;//返回
}
int main(){
cin>>n;//输入
while(n>0){
n-=f();//减法操作
cnt++;//统计
}
cout<<cnt<<endl;//输出
return 0;//好习惯养成
}