题解 | #学英语#
学英语
https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
num1 = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] num2 = [0, 0, 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] # 100以内: def n2w(x): if x < 20: word.append(num1[x]) else: word.append(num2[x // 10]) if x % 10 != 0: word.append(num1[x % 10]) # 1000以内 def hun(x): if x >= 100: word.append(num1[x // 100]) word.append('hundred') if x % 100 != 0: word.append('and') n2w(x % 100) else: n2w(x % 100) while True: try: n = int(input()) except: break else: word = [] a = n % 1000 # 一千以内 b = (n // 1000) % 1000 # 一千以上百万以内 c = (n // 1000000) % 1000 # 百万以上十亿以内 d = (n // 1000000000) % 1000 # 十亿以上 if d != 0: hun(d) word.append('billion') if c != 0: hun(c) word.append('million') if b != 0: hun(b) word.append('thousand') if a != 0: hun(a) print(' '.join(word))