题解 | #人民币转换#
人民币转换
https://www.nowcoder.com/practice/00ffd656b9604d1998e966d555005a4b
import math
def fun(x):
if x==0:
return ""
if x<=9:
return sz[x-1]
if x<=99:
if x//10!=1:
return sz[x//10-1]+"拾"+fun(x%10)
else:
return "拾"+fun(x%10)
if x<=999:
return sz[x//100-1]+"佰"+fun(x%100)
if x<=9999:
return sz[x//1000-1]+"仟"+fun(x%1000)
sz=["壹","贰","叁","肆","伍","陆","柒","捌","玖"]
l=input().split(".")
ls=[]
x=l[0]
danwei=["亿","万","元"]
for i in range(math.ceil(len(x)/4)):
ls.insert(0,int(x[-4:]))
x=x[:-4]
s=""
if not (len(ls)==1 and ls[0]==0):
for i in range(-1,len(ls)*-1-1,-1):
s=fun(ls[i])+danwei[i]+s
fs=int(l[1])
if fs==0:
s=s+"整"
else:
if fs//10==0:
s=s+sz[fs%10-1]+"分"
else:
if fs%10==0:
s=s+sz[fs//10-1]+"角"
else:
s=s+sz[fs//10-1]+"角"+sz[fs%10-1]+"分"
print("人民币"+s)

