Created
April 16, 2021 16:11
-
-
Save deeev-sb/7ce3d3e10283718f985c73b4cf62d58d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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