convert ten digits into a string:
rules for conversion:
separate the number into a set of four-three-three
Two consecutive numbers: double
Three consecutive numbers: triple
Four consecutive numbers: quadruple
sample input:9966777819
output should be:double nine double six triple seven eight one nine
Sample input2: 9999
Output should be: quadruple nine
Sample input3: 88
Output should be: double eight
def num_to_str(num:str):
prefix = ('', 'double ', 'triple ', 'quadruple ')
root = ('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')
reapets = 0
res = []
for i in range(len(num)):
if (i < (len(num)-1)) and (num[i] == num[i+1]):
reapets += 1
else:
res.append(prefix[reapets] + root[int(num[i])])
reapets = 0
return ' '.join(res)
for i in range(3):
number = input()
res = []
i = 4
num = number[:4]
while num:
res.append(num_to_str(num))
num = number[i:i+3]
i += 3
print(' '.join(res))
Comments
Leave a comment