practivceAlgorithm/백준
[백준][Python] 5397 키로거
findTheValue
2021. 7. 27. 00:19
포인터로 와리가리하면서 삽입, 출력해야하는문제 뭔가 insert를 써야할 것 같은 문제는
보통 stack을 2개쓰거나 heap을 두개쓰거나 하면 된다.
import sys
input = sys.stdin.readline
T = int(input())
for test in range(T):
L = input().rstrip()
left,right = [],[]
for chr in L:
if chr=="<":
if left:
right.append(left.pop())
elif chr==">":
if right:
left.append(right.pop())
elif chr=="-":
if left:
left.pop()
else:
left.append(chr)
answer = left + right[::-1]
print("".join(answer))