题解 | #学英语#

学英语

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

n = int(input())
ones = {
    0: "",
    1: "one",
    2: "two",
    3: "three",
    4: "four",
    5: "five",
    6: "six",
    7: "seven",
    8: "eight",
    9: "nine",
    10: "ten",
    11: "eleven",
    12: "twelve",
    13: "thirteen",
    14: "fourteen",
    15: "fifteen",
    16: "sixteen",
    17: "seventeen",
    18: "eighteen",
    19: "nineteen",
}
tens = {
    2: "twenty",
    3: "thirty",
    4: "forty",
    5: "fifty",
    6: "sixty",
    7: "seventy",
    8: "eighty",
    9: "ninety",
    1: "ten",
}
def transfer(attr):
    if 0 <= attr <= 19:
        return ones[attr]
    elif 20 <= attr <= 99:
        return tens[attr // 10] + ["" if attr % 10 == 0 else " "][0] + ones[attr % 10]
    elif 100 <= attr <= 999:
        return (
            ones[attr // 100]
            + " hundred "
            + ["" if attr % 100 == 0 else "and "][0]
            + transfer(attr % 100)
        )
if n <= 999:
    print(transfer(n))
elif 1000 <= n <= 999999:
    print(transfer(n // 1000) + " thousand " + transfer(n % 1000))
else:
    print(
        transfer(n // 1000000)
        + " million "
        + transfer((n % 1000000) // 1000)
        + " thousand "
        + transfer((n % 1000000) % 1000)
    )

一起讨论啊

全部评论

相关推荐

无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
ProMonkey2024:5个oc?厉害! 但是有一个小问题:谁问你了?😡我的意思是,谁在意?我告诉你,根本没人问你,在我们之中0人问了你,我把所有问你的人都请来 party 了,到场人数是0个人,誰问你了?WHO ASKED?谁问汝矣?誰があなたに聞きましたか?누가 물어봤어?我爬上了珠穆朗玛峰也没找到谁问你了,我刚刚潜入了世界上最大的射电望远镜也没开到那个问你的人的盒,在找到谁问你之前我连癌症的解药都发明了出来,我开了最大距离渲染也没找到谁问你了我活在这个被辐射蹂躏了多年的破碎世界的坟墓里目睹全球核战争把人类文明毁灭也没见到谁问你了(别的帖子偷来的,现学现卖😋)
点赞 评论 收藏
分享
评论
2
1
分享
牛客网
牛客企业服务