輸入一個數,將這個數的各個位相乘,求相乘後位個位數的次數
如輸入258,變換爲2*5*8=80,然後8*0=0,次數爲2。
輸入:2 5 8
輸出:2
python3(直接100%通過牛客):
import sys
def change_time(input_,temp):
str_ = str(input_)
mat = int(str_[0])
for i in range(1,len(str_)):
mat = mat*int(str_[i])
temp += 1
if 0<=mat<=9:
return temp
else:
return change_time(mat,temp)
for line in sys.stdin:
input_ = line.split()
if int(input_[0]) < 10:
print(0)
else:
result = change_time(int(input_[0]),0)
print(result)