4 条题解
-
5
这个swap给我干沉默了
def calm(a,b,op): a,b = b,a if op == "+": return a+b elif op == "-": return a-b elif op == "*": return a*b elif op == "/": return a/b l = input().split() operator = "+-*/" stack = [0]*10000 top = -1 for i in l: if i not in operator: top+=1 stack[top] = float(i) else: a = stack[top] top-=1 b = stack[top] top-=1 top+=1 stack[top]=calm(a,b,i) print("%.2f" %stack[top])
-
2
s = input() st = [0]* 1000 top = -1 s = s.split() temp = 0 for i in range(len(s)): if s[i] >= '0' and s[i] <= '9': top = top + 1 st[top] = int(s[i]) elif s[i] == '+': temp = st[top - 1] + st[top] top = top - 1 st[top] = temp elif s[i] == '-': temp = st[top - 1] - st[top] top = top - 1 st[top] = temp elif s[i] == '*': temp = st[top - 1]* st[top] top = top - 1 st[top] = temp elif s[i] == '/': temp = st[top - 1]/ st[top] top = top - 1 st[top] = temp print("%.2f" % st[0])
-
1
def calc(a,b,op): if op=='+': return a+b if op=='-': return a-b if op=='*': return a*b if op=='/': return a/b s=input() st=[0]*1000 top=-1 t=0 for i in range(len(s)): if '0'<=s[i]<='9': t=t*10+int(s[i]) elif s[i]==' ': top+=1 st[top]=t t=0 else: b=st[top] top-=1 a=st[top] top-=1 t=calc(a,b,s[i]) top+=1 st[top]=t print("%.2f"%st[0]) #对①空结果保留两位小数
-
-1
s=input() st=[0]1000 top=-1 x=0 for i in range(len(s)): if "0"<=s[i]<="9": x=x10+int(s[i]) elif s[i]" ": top+=1 st[top]=x x=0 else: num1=st[top] top-=1 num2=st[top] top-=1 if s[i]"+": x=num2+num1 elif s[i]"-": x=num2-num1 elif s[i]"": x=num2num1 elif s[i]=="/": x=num2/num1 print("%.2lf"%x)
- 1
信息
- ID
- 796
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 1091
- 已通过
- 217
- 上传者