题目:
考试题目和要点:
1、中文大写金额数字前应标明“人民币”字样。中文大写金额数字应用壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿、元、角、分、零、整等字样填写。
2、中文大写金额数字到“元”为止的,在“元”之后,应写“整字,如532.00应写成“人民币伍佰叁拾贰元整”。在”角“和”分“后面不写”整字。
3、阿拉伯数字中间有“0”时,中文大写要写“零”字,阿拉伯数字中间连续有几个“0”时,中文大写金额中间只写一个“零”字,如6007.14,应写成“人民币陆仟零柒元壹角肆分“。
4、10应写作“拾”,100应写作“壹佰”。例如,1010.00应写作“人民币壹仟零拾元整”,110.00应写作“人民币壹佰拾元整”
5、十万以上的数字接千不用加“零”,例如,30105000.00应写作“人民币叁仟零拾万伍仟元整”
解答:
难点:3.数字零的处理
z,x=input().split(".")
danwei=["万","亿"]
digit=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖']
def convertX(x):
tmp=""
jiao=int(x[0])
fen=int(x[1])
if jiao!=0:
tmp=tmp+digit[jiao]+"角"
if fen!=0:
tmp=tmp+digit[fen]+"分"
return tmp
#从低位到高位开始处理,每次处理四位
def convertZ(z):
tmp=""
z=int(z)
power=-1
while z:
cur=z%10000
ge=cur%10
shi=cur//10%10
bai=cur//100%10
qian=cur//1000%10
if power>=0:
tmp+=danwei[power]
#处理个位
if ge!=0:
tmp+=digit[ge]
#处理十位
if shi!=0:
tmp+='拾'
if shi!=1:
tmp+=digit[shi]
else:
if ge!=0 and (cur>99 or z>10000):
tmp+=digit[0]
#处理百位
if bai!=0:
tmp+='佰'+digit[bai]
else:
if shi!=0 and (cur>999 or z>10000):
tmp+=digit[0]
#处理千位
if qian!=0:
tmp+='仟'+digit[qian]
else:
if bai!=0 and z>10000:
tmp+=digit[0]
power+=1
if power>1:
power=0
z//=10000
return tmp[::-1]
res="人民币"
#只有整数
if x=='00':
res=res+convertZ(z)+"元整"
#只有小数
elif z=='0':
res=res+convertX(x)
#小数和整数都有
else:
res=res+convertZ(z)+"元"+convertX(x)
print(res)