题解 | #学英语#
学英语
https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
import sys
for line in sys.stdin:
innum = int(line)
one_word = {
1: "one",
2: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
8: "eight",
9: "nine",
10: "ten",
11: "eleven",
12: "twelve",
13: "thirteen",
14: "fourteen",
15: "fifteen",
16: "sixteen",
17: "seventeen",
18: "eighteen",
19: "nineteen",
20: "twenty",
30: "thirty",
40: "forty",
50: "fifty",
60: "sixty",
70: "seventy",
80: "eighty",
90: "ninety"
}
base_word = ["", "thousand", "million", "billion"]
if innum == 0:
print("zero")
exit()
else:
next_three = innum
final_word = []
base_i = 0
while next_three > 0:
this_three = next_three % 1000
next_three = int(next_three / 1000)
final_word.append(base_word[base_i])
base_i += 1
if this_three in one_word:
final_word.append(one_word[this_three])
else:
if this_three % 100 in one_word:
final_word.append(one_word[this_three % 100])
else:
if this_three % 10 in one_word:
final_word.append(one_word[this_three % 10])
if int(this_three / 10) % 10 * 10 in one_word:
final_word.append(one_word[int(this_three / 10) % 10 * 10])
if this_three >= 100 :
if this_three % 100 > 0:
final_word.append("and")
final_word.append("hundred")
final_word.append(one_word[int(this_three / 100)])
print(" ".join(final_word[::-1]))
