[READ-ONLY] Mirror of https://github.com/shuuji3/competitive-programming. 馃洬 Codes submitted to competitive programming platforms
aizu-online-jadge
aoj
atcoder
hackerrank
leetcode
460 B
21 lines
1ops = input().split()
2stack = []
3
4for op in ops:
5 if op == '+':
6 op2 = stack.pop()
7 op1 = stack.pop()
8 stack.append(op1 + op2)
9 elif op == '-':
10 # ['3', '4', '-'] should be '-1'
11 op2 = stack.pop()
12 op1 = stack.pop()
13 stack.append(op1 - op2)
14 elif op == '*':
15 op2 = stack.pop()
16 op1 = stack.pop()
17 stack.append(op1 * op2)
18 else:
19 stack.append(int(op))
20
21print(stack.pop())