题解 | #学英语#

学英语

https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc

s=input()
a=""
for i in range(1,len(s)+1):
    if (i-1)%3==0 and i!=1:
        a=a+","
    a=a+s[-i]
s=a[::-1]
n=s.split(",")

num1 = ["","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"]
num2 = ["","","twenty","thirty","forty", "fifty","sixty","seventy","eighty","ninety"]
num3 = ["","thousand","million","billion"]
def f(n):
    if int(n)<100:
        if int(n)==0:
            return
        elif int(n)<21:
            return num1[int(n)]
        else:
            if int(n[-1])!=0:
                return num2[int(n[-2])]+" "+num1[int(n[-1])]
            else:
                return num2[int(n[-2])]
    else:
        if int(n[1:])==0:
            return num1[int(n[-3])]+" "+"hundred"
        elif int(n[-2])<2:
            return num1[int(n[-3])]+" "+"hundred"+" and "+num1[int(n[1:])]
        else:
            return num1[int(n[-3])]+" "+"hundred"+" and "+num2[int(n[-2])]+" "+num1[int(n[-1])]
for i in range(len(n)):
    print(f(n[i])+" "+num3[len(n)-i-1],end=" ")



全部评论

相关推荐

gcniz:一天写两千行你闹呢
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
09-10 15:43
不想上班蚊不叮在走神:华子是这样的。我投递了,还有其他华子内部人加我,不知道从哪搞的微信号,还要给我打电话劝我改投递方向。直接不鸟就行了
点赞 评论 收藏
分享
10-23 11:53
门头沟学院 Java
投递华为等公司10个岗位 >
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务