본문 바로가기
leetcode 풀이/큐, 스택 (Array)

boj-5397. 키 로거

by 튼튼한개발자 2023. 1. 20.
import sys

for _ in range(int(input())):
    left = []
    right = []

    input = sys.stdin.readline()
    
    for c in input :
        if c == "<":
            if left :
                right.append(left.pop())
        elif c == ">":
            if right :
                left.append(right.pop())
        elif c == "-":
            if left :
                left.pop()
        else :
            left.append(c)

    left.extend(right)
    print("".join(list(left)))

댓글