Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created January 11, 2020 03:58
Show Gist options
  • Save inspirit941/50a7396e07a7dab8418d620c1a54ee74 to your computer and use it in GitHub Desktop.
Save inspirit941/50a7396e07a7dab8418d620c1a54ee74 to your computer and use it in GitHub Desktop.
import sys
n = int(sys.stdin.readline().replace("\n",""))
for _ in range(n):
# 글자를 입력받는 stack left, 커서 이동할 때 사용할 stack right.
left, right = [], []
string = list(sys.stdin.readline().replace("\n",""))
for value in string:
# 커서를 뒤로 옮길 경우, left에 값이 있다면 left 마지막 값을 right로 옮긴다.
if value == "<":
if len(left) != 0:
right.append(left.pop())
# 커서를 앞으로 옮길 경우, right에 값이 있다면 right 마지막 값을 left로 옮긴다.
elif value == ">":
if len(right) != 0:
left.append(right.pop())
# 백스페이스로 글자 지우기.
elif value == "-":
if len(left) != 0:
left.pop()
else:
left.append(value)
left_string = "".join(left)
# right로 이동시켰던 값은 stack에 입력순서의 역순으로 쌓여 있으므로, 재배열해준다.
right_string = "".join(right[::-1])
print(left_string+right_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment