5 条题解

  • 1
    @ 2024-11-23 8:47:38
    def convert(s1):     
        st=[0]*100
        top=-1
        s2="" 
        a=""
        for i in range(len(s1)):
            if '0'<=s1[i]<='9':
                a+=s1[i]
            else:
                if '0'<=s1[i-1]<='9':
                    s2=s2+a+" "
                    a=""
                if s1[i]=="(":
                    top+=1
                    st[top]=s1[i]
                else:
                    while top>-1 and yxj[s1[i]]<=yxj[st[top]]:
                        s2=s2+st[top]+" "
                        top-=1
                    if s1[i]==")":
                        top-=1
                    else:
                        top+=1
                        st[top]=s1[i]
        s2=s2+a+" "
        while top>-1:
            s2=s2+st[top]+" "
            top-=1
        return s2
    yxj={"+":2,"-":2,"*":3,"/":3,"(":0,")":1}  
    s1=input()
    print(convert(s1))
    

    信息

    ID
    800
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    840
    已通过
    167
    上传者