题解 | #学英语#

学英语

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

import sys

for line in sys.stdin:
    innum = int(line)

one_word = {
    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",
    20: "twenty",
    30: "thirty",
    40: "forty",
    50: "fifty",
    60: "sixty",
    70: "seventy",
    80: "eighty",
    90: "ninety"
}

base_word = ["", "thousand", "million", "billion"]

if innum == 0:
    print("zero")
    exit()
else:
    next_three = innum
    final_word = []
    base_i = 0
    while next_three > 0:
        this_three = next_three % 1000
        next_three = int(next_three / 1000)
        final_word.append(base_word[base_i])
        base_i += 1

        if this_three in one_word:
            final_word.append(one_word[this_three])
        else:
            if this_three % 100 in one_word:
                final_word.append(one_word[this_three % 100])
            else:
                if this_three % 10 in one_word:
                    final_word.append(one_word[this_three % 10])
                if int(this_three / 10) % 10 * 10 in one_word:
                    final_word.append(one_word[int(this_three / 10) % 10 * 10])
            if this_three >= 100 :
                if this_three % 100 > 0:
                    final_word.append("and")
                final_word.append("hundred")
                final_word.append(one_word[int(this_three / 100)])
    print(" ".join(final_word[::-1]))

        
        

    

全部评论

相关推荐

牛可乐121381:卖课的
点赞 评论 收藏
分享
02-08 15:53
门头沟学院 Java
CoderEcho:让公司知道便宜没好货
点赞 评论 收藏
分享
03-14 11:58
门头沟学院 Java
腾讯暑期实习java选手,完全不懂C++,貌似游戏行业都是用C++的而且天美好像在成都,个人比较想去上海或深圳
siestaaaaaa:天美不止在成都,深圳上海都有。 游戏服务器也不全是cpp,至少我们项目是java ,但是工作中什么语言都会用到,比如cpp、lua、py等等,语言本身其实不重要
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务