forked from Zy0ung/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
45 lines (39 loc) · 940 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Authored by : gusdn3477
# Co-authored by : -
# Link : http://boj.kr/db333837b5af4d84a2a5ba1dc83d2086
import sys
from collections import deque
def input():
return sys.stdin.readline().rstrip()
N = int(input())
arr = input()
oper = '+-*/'
dic = {}
stack = []
num = deque()
for i in range(N):
num.append(int(input()))
for i in arr:
if i not in dic and i not in oper:
dic[i] = num.popleft()
for i in arr:
if i not in oper:
stack.append(dic[i])
else:
if i == '+':
a = stack.pop()
b = stack.pop()
stack.append(b+a)
elif i == '-':
a = stack.pop()
b = stack.pop()
stack.append(b-a)
elif i == '*':
a = stack.pop()
b = stack.pop()
stack.append(b*a)
else:
a = stack.pop()
b = stack.pop()
stack.append(b/a)
print(f"{stack[0]:.2f}")