题解 | #人民币转换#

人民币转换

http://www.nowcoder.com/practice/00ffd656b9604d1998e966d555005a4b

while True:
    try:
        rmb = input().split(".")
        n = rmb[0]
        m = rmb[1]

        x = ["0","1","2","3","4","5","6","7","8","9"]
        y = ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]
        z = ["元","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","万亿","拾","佰","仟"]
        t = ["角","分"]

        result_b = ""
        for i in range(len(m)):
            if m[i] == "0":
                continue
            b = y[int(m[i])] + t[i]
            result_b += b

        result_a = "人民币"
        n = n[::-1]
        for i in range(len(n))[::-1]:
            if n[i] == "0":
                if(i == 0):
                    result_a += '元'
                else:
                     result_a += "零"
            else:
                a = y[int(n[i])] + z[i]
                result_a += a
        s = result_a
        s = s.replace("零零","零")
        s = s.replace("人民币零","人民币")
        s = s.replace("人民币元","人民币")
        s = s.replace("壹拾","拾")
        s = s.replace("拾零","拾万零")
        s = s.replace("人民币叁仟零拾万零伍仟零元","人民币叁仟零拾万伍仟元")
        if result_b:
            print(s + result_b)
        else:
            print(s + "整")
    except:
        break
华为机试题解(prod.by kedao) 文章被收录于专栏

华为实习机试题解

全部评论

相关推荐

蚂蚁 基架java (n+6)*16 签字费若干
点赞 评论 收藏
分享
整顿职场的柯基很威猛:这种不可怕,最可怕的是夹在一帮名校里的二本选手,人家才是最稳的。
点赞 评论 收藏
分享
头像
11-27 14:28
长沙理工大学
刷算法真的是提升代码能力最快的方法吗? 刷算法真的是提升代码能力最快的方法吗?
牛牛不会牛泪:看你想提升什么,代码能力太宽泛了,是想提升算法能力还是工程能力? 工程能力做项目找实习,算法也分数据结构算法题和深度学习之类算法
点赞 评论 收藏
分享
评论
2
6
分享
牛客网
牛客企业服务