题解 | #学英语#

学英语

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

num = [1,2,3,4,5,6,7,8,9]
word_1 = ['one','two','three','four','five','six','seven','eight','nine']
word_2 = ['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
num_10 = [11,12,13,14,15,16,17,18,19]
word_3 = ['ten','eleven','twelve','thirteen','fourtee','fifteen','sixteen','seventeen','eighteen','nineteen']


def read(three_num:int):
    out = []

    num_100 = three_num//100
    num_1 = three_num%10
    num_10=  (three_num - num_100*100 - num_1)//10

    if num_100:
        out.append(word_1[num_100-1])
        out.append("hundred")
    
    if num_10:
        if num_100:
            out.append("and")
        if num_10 >=2:
            out.append(word_2[num_10-2])
        elif num_10 == 1:
            out.append(word_3[num_1-10])
    
    if num_1 and num_10!=1:
        if num_100 and not num_10:
            out.append("and")
        out.append(word_1[num_1-1])

    return out

s = input()

ls = len(s)
out = []
if ls<=3:
    out.extend(read(int(s)))
elif ls<=6:
    out.extend(read(int(s[:-3])))
    out.append("thousand")
    out.extend(read(int(s[-3:])))
elif ls > 6:
    out.extend(read(int(s[:-6])))
    out.append("million")
    out.extend(read(int(s[-6:-3])))
    out.append("thousand")
    out.extend(read(int(s[-3:])))


print(" ".join(out))

全部评论

相关推荐

走不到的路就这样算了吗:大佬硬气
点赞 评论 收藏
分享
爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务