import sys
input = sys.stdin.readline
infix = input().rstrip() + ')'
dic = {'(': 0, '*': 1, '/': 1, '+': 2, '-': 2}
stack = ['(']
i = 0
while stack:
if infix[i].isalpha():
print(infix[i], end='')
elif infix[i] == '(':
stack.append('(')
elif infix[i] == ')':
while stack and stack[-1] != '(':
print(stack.pop(), end='')
stack.pop()
else: # + - * /
if dic[infix[i]] == dic[stack[-1]]:
print(stack.pop(), end='')
elif dic[infix[i]] > dic[stack[-1]]:
while stack[-1] != '(':
print(stack.pop(), end='')
stack.append(infix[i])
i += 1
작년 초에 자료구조 공부할 때 C로 만들었던 기억이 있다. 추억이 새록새록..