每天都很困


私信TA

用户名:uq_70603251354

访问量:202

签 名:

等  级
排  名 25286
经  验 552
参赛次数 0
文章发表 5
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:
只需要单独考虑每四位的一个读法即可

就是不停地分类分类分类
参考代码:

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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区