Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions ioo5959/구현/5397.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
input = sys.stdin.readline

n = int(input())
#시도 1. list 하나를 만들어 index를 이동해 삽입 삭제 -> 시간초과
# for _ in range(n):
# lis = list(input())
# result = []
# idx = 0
# for x in lis:
# if x == '<':
# if idx == 0:
# idx = 0
# else:
# idx -= 1
# elif idx != len(lis) - 1 and x == '>':
# idx += 1
# elif x == '-' and result != []:
# result.pop()
# else:
# result.insert(idx,x)
# idx += 1
#
# print(''.join(result))

for _ in range(n):
line = input().strip()
left = []
right = []

for ch in line:
if ch == '<':
if left:
right.append(left.pop())
elif ch == '>':
if right:
left.append(right.pop())
elif ch == '-':
if left:
left.pop()
else:
left.append(ch)

print(''.join(left + right[::-1]))