人民币转换

题目描述

考试题目和要点:

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

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

3、阿拉伯数字中间有“0”时,中文大写要写“零”字,阿拉伯数字中间连续有几个“0”时,中文大写金额中间只写一个“零”字,如¥6007.14,应写成“人民币陆仟零柒元壹角肆分“。(40分)

输入描述:

输入一个double数

输出描述:

输出人民币格式

示例1

输入

151121.15

输出

人民币拾伍万壹仟壹佰贰拾壹元壹角伍分

答案:

import re

try:
    while True:
        mons = [int(i) for i in input().split('.')]
        comm_num = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
        res = '人民币'
        if mons[0] == 0:
            res += comm_num[mons[1] // 10] + '角' + comm_num[mons[1] % 10] + '分' 
        else:
            temp = mons[0] // 100000000
            if temp != 0:
                if temp >= 1000:
                    res += comm_num[temp // 1000] + '仟'
                if temp >= 100:
                    res += comm_num[temp % 1000 // 100] + '佰'
                if temp >= 10:
                    res += comm_num[temp % 100 // 10] + '拾'
                res += comm_num[temp % 10] + '亿'
            else:
                res += comm_num[temp]
            mons[0] = mons[0] % 100000000
            temp = mons[0] // 10000
            if temp != 0:
                if temp >= 1000:
                    res += comm_num[temp // 1000] + '仟'
                if temp >= 100:
                    res += comm_num[temp % 1000 // 100] + '佰'
                if temp >= 10:
                    res += comm_num[temp % 100 // 10] + '拾'
                res += comm_num[temp % 10] + '万'
            else:
                res += comm_num[temp]    
            mons[0] = mons[0] % 10000
            temp = mons[0] // 1000
            if temp != 0:
                res += comm_num[temp] + '仟'
            else:
                res += comm_num[temp]
            mons[0] = mons[0] % 1000
            temp = mons[0] // 100
            if temp != 0:
                res += comm_num[temp] + '佰'
            else:
                res += comm_num[temp]
            mons[0] = mons[0] % 100
            temp = mons[0] // 10
            if temp != 0:
                res += comm_num[temp] + '拾'
            else:
                res += comm_num[temp]
            mons[0] = mons[0] % 10
            if mons[0] != 0:
                res += comm_num[mons[0]] + '元'
            if mons[1] == 0:
                res += '整'
            else:
                res += comm_num[mons[1] // 10] + '角' + comm_num[mons[1] % 10] + '分' 
        
        for i in re.findall(r'零+', res):
            res = res.replace(i, '零')
        res = res.replace('人民币零', '人民币')
        res = res.replace('零角', '')
        res = res.replace('零分', '')
        res = res.replace('人民币壹拾', '人民币拾')
        
        print(res)
except:
    pass

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值