BOJ - 5397 - 키로거
Updated:
import sys
def solution():
T = int(sys.stdin.readline())
for _ in range(T):
L = sys.stdin.readline().strip()
s, e = [], []
for l in L:
if l == '<':
if s:
e.append(s.pop())
elif l == '>':
if e:
s.append(e.pop())
elif l == '-':
if s:
s.pop()
else:
s.append(l)
s.extend(reversed(e))
print(''.join(s))
solution()
https://www.acmicpc.net/problem/5397
Leave a comment