人民币转换

 
  • 题目
  • 题解(152)
  • 讨论(254)
  • 排行
  • 面经
    new
 时间限制:1秒  空间限制:32M
知识点字符串
warning 校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。

描述

考试题目和要点:

1、中文大写金额数字前应标明“人民币”字样。中文大写金额数字应用壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿、元、角、分、零、整等字样填写。

2、中文大写金额数字到“元”为止的,在“元”之后,应写“整字,如532.00应写成“人民币伍佰叁拾贰元整”。在”角“和”分“后面不写”整字。

3、阿拉伯数字中间有“0”时,中文大写要写“零”字,阿拉伯数字中间连续有几个“0”时,中文大写金额中间只写一个“零”字,如6007.14,应写成“人民币陆仟零柒元壹角肆分“。
4、10应写作“拾”,100应写作“壹佰”。例如,1010.00应写作“人民币壹仟零拾元整”,110.00应写作“人民币壹佰拾元整”
5、十万以上的数字接千不用加“零”,例如,30105000.00应写作“人民币叁仟零拾万伍仟元整”

 

输入描述:

输入一个double数

输出描述:

输出人民币格式

示例1

输入:
151121.15
输出:
人民币拾伍万壹仟壹佰贰拾壹元壹角伍分

示例2

输入:
1010.00
输出:
人民币壹仟零拾元整
 
 
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
        #print(result_b)
        result_a = "人民币"
        n = n[::-1]
        for i in range(len(n))[::-1]:
            if n[i] == '0':
                result_a+=''
            else:
                result_a += (y[int(n[i])] + z[i])
        s = result_a
        s = s.replace("人民币零","人民币")
        s = s.replace("壹拾","")
        if result_b:
            print(s + result_b)
        else:
            print(s + "")
    except:
        break

 

posted @ 2023-07-02 16:39  乐乐章  阅读(43)  评论(0编辑  收藏  举报