작성
·
141
0
n = input()
stack = []
result = ''
for i in n:
if i.isnumeric():
result += i
else:
if len(stack) == 0:
stack.append(i)
continue
if i == '*' or i == '/':
if stack[-1] == '*' or stack[-1] == '/':
result += stack[-1]
stack.pop()
stack.append(i)
elif i == '+' or i == '-':
while stack and stack[-1] != '(':
result += stack[-1]
stack.pop()
stack.append(i)
elif i == '(':
stack.append(i)
elif i == ')':
while stack and stack[-1] != '(':
result += stack[-1]
stack.pop()
stack.pop()
for x in stack[::-1]:
if x != '(':
result += x
print(result)