sad


私信TA

用户名:dotcpp0636157

访问量:595

签 名:

等  级
排  名 2272
经  验 2290
参赛次数 0
文章发表 13
年  龄 0
在职情况 学生
学  校 asd
专  业

  自我简介:

TA的其他文章

最多约数问题
浏览:83
核电站问题
浏览:14

解题思路:

注意事项:

参考代码:

syouxianji = {'^':6,'/':4,'*':3,'-':2,'+':1,'':0,'(':0,')':0}
try:
   s = input()
   while s!='#':
       slis = []
       t = ''
       for i in range(len(s)):
           if s[i].isdigit():
               t+=s[i]
               if i==len(s)-1 and t!='':
                   slis.append(t)
           else:
               if t!='':
                   slis.append(t)
               slis.append(s[i])
               t=''
       ss = []
       t = 2
       i=0
       while i<len(slis):
           if slis[i] == '(':
               ss.append(i)
           elif slis[i]==')':
               l=ss.pop()
               try:
                   youfuhao = slis[i + 1]
               except:
                   youfuhao = ''
               if l==0:
                   zuofuhao = ''
               else:zuofuhao = slis[l - 1]
               try:
                   zhongfuhao=slis[i-t]
               except:zhongfuhao=''
               if i-2==l or \
                       (zuofuhao == '(' and youfuhao == ')')\
                       or (  (zhongfuhao == '*') and ((syouxianji[zhongfuhao] >= syouxianji[zuofuhao]) and (syouxianji[zhongfuhao]+1 >= syouxianji[youfuhao]))) \
                       or ((zhongfuhao == '/') and ((syouxianji[zhongfuhao] > syouxianji[zuofuhao]) and (
                              syouxianji[zhongfuhao] >= syouxianji[youfuhao]))) \
                       or ((zhongfuhao=='-' or zhongfuhao == '^') and ((syouxianji[zhongfuhao] > syouxianji[zuofuhao]) and (
                               syouxianji[zhongfuhao] > syouxianji[youfuhao]))) \
                       or ((zhongfuhao == '+' ) and ( syouxianji[zhongfuhao] >= syouxianji[zuofuhao]) and (
                                syouxianji[zhongfuhao] >= syouxianji[youfuhao])):
                       if youfuhao==')':
                           t+=2
                       slis.pop(i)
                       slis.pop(l)
                       i-=2
               else:
                   if youfuhao == ')':
                       t += 4
           i+=1
       print(''.join(slis))
       s = input()
except:pass

 

0.0分

0 人评分

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

编程语言转换

万能编程问答

代码解释器

  评论区