From e859de493e28a867093401650909327e37d8856a Mon Sep 17 00:00:00 2001 From: ioo5959 Date: Thu, 10 Jul 2025 14:45:59 +0900 Subject: [PATCH] =?UTF-8?q?5397=5F=ED=82=A4=EB=A1=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "ioo5959/\352\265\254\355\230\204/5397.py" | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "ioo5959/\352\265\254\355\230\204/5397.py" diff --git "a/ioo5959/\352\265\254\355\230\204/5397.py" "b/ioo5959/\352\265\254\355\230\204/5397.py" new file mode 100644 index 0000000..198b6d4 --- /dev/null +++ "b/ioo5959/\352\265\254\355\230\204/5397.py" @@ -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])) \ No newline at end of file