Skip to content

Instantly share code, notes, and snippets.

@deeev-sb
Created April 16, 2021 16:11
Show Gist options
  • Save deeev-sb/7ce3d3e10283718f985c73b4cf62d58d to your computer and use it in GitHub Desktop.
Save deeev-sb/7ce3d3e10283718f985c73b4cf62d58d to your computer and use it in GitHub Desktop.
text = input()
answer = ''
stack = [] # 연산자 관리용
for t in text :
if t.isalpha() :
answer += t
else :
if t == '(' :
stack.append(t)
elif t == '*' or t == '/' :
while stack and (stack[-1] == '*' or stack[-1] == '/') :
answer += stack.pop()
stack.append(t)
elif t == '+' or t == '-' :
while stack and stack[-1] != '(' :
answer += stack.pop()
stack.append(t)
elif t == ')' :
while stack and stack[-1] != '(' :
answer += stack.pop()
stack.pop() # '('를 빼는 작업
while stack :
answer += stack.pop()
print(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment