解题思路:
只需要单独考虑每四位的一个读法即可
就是不停地分类分类分类
参考代码:
def func(): global ans,mzero1,mzero2,mzero3,mfour for i in range(len(ss)): #这两个if是用来判断是否添加万和亿的 if i==4 and mfour==1: ans=ans+'wan ' if i==8 and mfour==2: ans=ans+'yi ' #接下来的语句其实就是每四位进行一个读法的转换 每四位除了单位不一样 读法是一样的 if (i+1)%4==1 and int(ss[i])!=0: ans+=dic[int(ss[i])]+' ' elif (i+1)%4==1 and int(ss[i])==0: mzero1=True elif (i+1)%4==2 and int(ss[i])!=0: if int(ss[i])==1: ans+='shi ' else: ans+='shi '+dic[int(ss[i])]+' ' elif (i+1)%4==2 and int(ss[i])==0: mzero2=True elif (i+1)%4==3 and int(ss[i])!=0: if int(ss[i])==1: if mzero1==False and mzero2==True: ans+='ling bai ' else: ans+='bai ' else: if mzero1==False and mzero2==True: ans+='ling bai '+dic[int(ss[i])]+' ' else: ans+='bai '+dic[int(ss[i])]+' ' elif (i+1)%4==3 and int(ss[i])==0: mzero3=True elif (i+1)%4==0: if int(ss[i])!=0: if int(ss[i])==1: if (mzero1==False and mzero2==True and mzero3==True) or (mzero1==True and mzero2==False and mzero3==True) or (mzero1==False and mzero2==False and mzero3==True): ans+='ling qian ' else: ans+='qian ' else: if (mzero1==False and mzero2==True and mzero3==True) or (mzero1==True and mzero2==False and mzero3==True) or (mzero1==False and mzero2==False and mzero3==True): ans+='ling qian '+dic[int(ss[i])]+' ' else: ans+='qian '+dic[int(ss[i])]+' ' else: if not (mzero1==True and mzero2==True and mzero3==True): ans+='ling ' mfour+=1 mzero1=False mzero2=False mzero3=False while True: try: x=int(input()) ss=str(x)[::-1] ans='' dic={0:'ling',1:'yi',2:'er',3:'san',4:'si',5:'wu',6:'liu',7:'qi',8:'ba',9:'jiu'} #用来记录零的个数 区分0的作用是ling还是shi、bai、qian mzero1=False mzero2=False mzero3=False mfour=0 func() lst=ans.strip().split(' ') lst.reverse() ans=' '.join(lst) print(ans) except: break
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:516 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:974 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C++代码)(手动优化一下计算)浏览:1286 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)for循环浏览:1131 |
简单的a+b (C语言代码)浏览:632 |
完数 (C语言代码)浏览:693 |
找出最长的字符串来 (C语言代码)浏览:1771 |
盐水的故事 (C语言代码)浏览:1529 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:406 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:502 |