1 걸린 시간 : 20m
2 사용한 자료구조 및 개념 : 스택
💡 문제풀이 아이디어 및 어려웠던 점
💫 아이디어
1️⃣ 피연산자가 나오면 stack에 push(append)
2️⃣ 연산자가 나오면 pop
👻 어려웠던 점
Solution Code & 주석
tc = int(input())
temp = input()
num_lst = [0] * tc
for t in range(tc):
num_lst[t] = int(input())
stack = []
for i in temp:
if 'A' <= i <= 'Z':
stack.append(num_lst[ord(i) - ord('A')])
else:
str2 = stack.pop()
str1 = stack.pop()
if i == '+':
stack.append(str1 + str2)
elif i == '-':
stack.append(str1 - str2)
elif i == '*':
stack.append(str1 * str2)
elif i == '/':
stack.append(str1 / str2)
print('%.2f' % stack[0])
'💡Algorithm > python' 카테고리의 다른 글
[python]1966_프린터 큐 (0) | 2023.07.04 |
---|---|
[python]10866_덱2 (0) | 2023.07.03 |
[python]2164_카드2 (0) | 2023.06.30 |
[python]1158_요세푸스 문제 (2) | 2023.06.29 |
[python]18258_큐2 (0) | 2023.06.29 |