题解 | #学英语#
学英语
https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
# 2024年11月8日 周五 下午16:07 # long类型是一种整数数据类型,通常用于存储较大范围的整数值 # 2.每三位数后记得带上计数单位 分别是thousand, million, billion. # 3.公式:百万以下千以上的数 X thousand X, 10亿以下百万以上的数:X million X thousand X, 10 亿以上的数:X billion X million X thousand X. 每个X分别代表三位数或两位数或一位数。 # 1,652,510: one million six hundred and fifty two thousand five hundred and ten num1 = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twleven", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", ] num2 = [ 0, 0, "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", ] def f100(n): if n > 0: # 这个n > 0一定要写 if n < 20: word.append(num1[n]) elif 20 <= n < 100: # 39//30 word.append(num2[n // 10]) if n % 10 != 0: word.append(num1[n % 10]) def f1000(n): if n >= 100: # 789 word.append(num1[n // 100]) word.append("hundred") if n % 100 != 0: word.append("and") f100(n % 100) # 注意这里的缩进 n = int(input()) word = [] # 处理n a = n % 1000 b = (n // 1000) % 1000 # thousand c = (n // 1000000) % 1000 # million d = (n // 1000000000) % 1000 # billion if d > 0: f1000(d) word.append("billion") if c > 0: f1000(c) word.append("million") if b > 0: f1000(b) word.append("thousand") if a > 0: f1000(a) print(*word)