Baekjoon #1935

Baekjoon #1935

1개의 풀이 · Python

문제 원문 보기 ↗

SOLUTION INFO

Python · main.py

main.py
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}")

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.