题解 | #人民币转换#

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

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

# 全局变量
alls = ['零','壹','贰', '叁','肆','伍','陆','柒','捌','玖','拾','佰','仟','万','亿','元','角','分','整']
# 处理小数点后的
def xs(s):
    re = ''
    if s == '00':
        re = '整'
    else:
        jiao = ''
        fen = ''
        if s[0] != '0':
            jiao = alls[int(s[0])] + '角'
        if s[1] != '0':
            fen = alls[int(s[1])] + '分'
        re = jiao + fen
    return re


def gw(s): # 处理个位
    if s[0] == '0':
        return ''
    else:
        return alls[int(s[0])] + '元'


def sw(s): # 处理十位
    re = ''
    if s == '10':
        re = '拾元整'
    else:
        re = alls[int(s[0])] + '拾' + gw(s[1])
        re = re.replace('壹拾','拾')
    return  re

def shiwangw(s): # 处理十位
    return alls[int(s[0])]


def shiwanshiwei(s): # 处理十位
    re = ''
    if s == '10':
        re = '拾'
    else:
        re = alls[int(s[0])] + '拾' + shiwangw(s[1])
        re = re.replace('壹拾','拾')
    return  re

def baiwei(s): # 处理百位
    re = ''
    if s[1:] =='00':
        re = alls[int(s[0])] + '佰元整'
    else:
        if s[1] == '0':
            re = alls[int(s[0])] + '佰' +'零' + gw(s[2])
        else:
            re = alls[int(s[0])] + '佰' + sw(s[1:])
    return re

def qianwei(s): # 处理千位
    re = ''
    if s[1:] == '000':
        re = alls[int(s[0])] + '仟元整'
    elif s[1:3] == '00':
        re = alls[int(s[0])] + '仟' + '零' + gw(s[-1])
    elif s[1] == '0':
        re = alls[int(s[0])] + '仟' + '零' + sw(s[-2:])
    else:
        re = alls[int(s[0])] +  '仟' + baiwei(s[1:])
    return re


def wanwei(s):
    re = ''
    if s[1:] == '0000':
        re = alls[int(s[0])] + '万元整'
    elif s[1:4] == '000':
        re = alls[int(s[0])] + '万' + '零' + gw(s[-1])
    elif s[1:3] == '00':
        re = alls[int(s[0])] + '万' + '零' + sw(s[-2:])
    elif s[1] == '0':
        re = alls[int(s[0])] + '万' + '零' + baiwei(s[-3:])
    else:
        re = alls[int(s[0])] + '万' + qianwei(s[1:])
    return re


def shiwan(s):
    re = ''
    if s[1:] == '00000':
        re = alls[int(s[0])] + '拾万元整'
    elif s[1:5] == '0000':
        re = alls[int(s[0])] + '拾万' + '零' + gw(s[-1])
    elif s[1:4] == '000':
        re = alls[int(s[0])] + '拾万' + '零' + sw(s[-2:])
    elif s[1:3] == '00':
        re = alls[int(s[0])] + '拾万' + '零' + baiwei(s[-3:])
    elif s[1] == '0':
        re = alls[int(s[0])] + '拾万' + '零' + qianwei(s[-4:])
    else:
        re = shiwanshiwei(s[:2]) + '万' + qianwei(s[2:])
    return re


s = input()
# s = '151121.15'
zs, xsd = map(str, s.split('.'))
str_xs = xs(xsd)
zd = len(zs)
str_zs = ''
if zd == 1:
    str_zs = gw(zs)
elif zd == 2:
    str_zs = sw(zs)
elif zd == 3:
    str_zs = baiwei(zs)
elif zd == 4:
    str_zs = qianwei(zs)
elif zd == 5:
    str_zs = wanwei(zs)
elif zd == 6:
    str_zs = shiwan(zs)
print('人民币' + str_zs + str_xs)





全部评论

相关推荐

点赞 评论 收藏
分享
过往烟沉:我说什么来着,java就业面就是广!
点赞 评论 收藏
分享
11-02 09:49
已编辑
货拉拉_测试(实习员工)
热爱生活的仰泳鲈鱼求你们别卷了:没事楼主,有反转查看图片
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务