题解 | #学英语#
学英语
https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
import sys
n = int(input())
a = n % 1000
b = (n//1000) % 1000
c = (n//1000000) % 1000
d = n // 1000000000
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'
]
def n2w(n):
if n > 0:
if n < 20: #0-20的情况
word.append(num1[n])
else: #几十几
word.append(num2[n//10])
if n % 10 != 0:
word.append(num1[n%10])
def hun(n):
if n >= 100:
word.append(num1[n//100]) #百位
word.append('hundred')
if n % 100 != 0: #有十位数
word.append('and')
n2w(n%100)
word = []
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))

海康威视公司福利 1182人发布
查看17道真题和解析