解题思路:
注意事项:
参考代码:
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 人评分
三进制小数 (C语言代码)浏览:1017 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:717 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:490 |
C语言程序设计教程(第三版)课后习题10.1 (Java代码)浏览:1436 |
【明明的随机数】 (C++代码)浏览:779 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:958 |
简单的a+b (C语言代码)浏览:681 |
WU-拆分位数 (C++代码)浏览:779 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:653 |
字符逆序 (C语言代码)浏览:636 |