题解 | #人民币转换#
矩阵乘法
http://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
while 1:
try:
s=input()
q,h=s.strip().split('.')[0],s.strip().split('.')[1]
n=float(s)
d={'0':'零','1':'壹','2':'贰','3':'叁','4':'肆','5':'伍','6':'陆','7':'柒','8':'捌','9':'玖'}
d2={0:'',1:'拾',2:'佰',3:'仟',4:'万',5:'亿'}
s='人民币'
if q !='0':
ql=list(q)
l=[]
while len(ql)>=4:
l.append(''.join(ql[-4::]))
for _ in range(4):
ql.pop()
if ql:
l.append(''.join(ql[::]))
# print(l)
sl=[]
for i in range(len(l)):
ss=''
le=len(l[i])
c=1
for j in range(le):
if l[i][j]!='0':
if l[i][j]=='1' and le-j-1==1:
ss+=d2[le-j-1]
else:
ss+=(d[l[i][j]]+d2[le-j-1])
c=1
elif l[i][j]=='0' and c:
ss+=d[l[i][j]]
c=0
if i>=1:
ss+=d2[i+3]
sl.append(ss)
sl.reverse()
s+=(''.join(sl)+'元').replace('拾零','拾').replace('仟零元','仟元')
if h=='00':
s+='整'
elif h !='00':
if h[0]!='0':
s+=d[h[0]]+'角'
if h[1]!='0':
s+=d[h[1]]+'分'
print(s)
except:
break