-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_1935.py
More file actions
32 lines (27 loc) · 837 Bytes
/
Copy pathbj_1935.py
File metadata and controls
32 lines (27 loc) · 837 Bytes
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
import sys
from collections import deque
# sys.stdin = open('bj_1935_in.txt', 'r')
open = sys.stdin.readline
stack = deque()
number = []
n = int(input())
command = input().strip()
for _ in range(n):
number.append(int(input().strip())) # 문자별 숫자 치환값
# print(ord('A'))
for ch in command:
if 'A' <= ch <= 'Z': #대문자면
stack.append(number[ord(ch) - ord('A')])
else: #문자가 아니면
back_number = stack.pop()
front_number = stack.pop()
if ch == '+':
result = front_number + back_number
elif ch == '-':
result = front_number - back_number
elif ch == '*':
result = front_number * back_number
elif ch == '/':
result = front_number / back_number
stack.append(result)
print(f"{stack[0]:.2f}")