BOJ - 1406 - 에디터

Updated:


import sys
import collections

def solution():
    left = collections.deque(sys.stdin.readline()[:-1])
    right = collections.deque()

    N = int(input())

    for _ in range(N):
        command = sys.stdin.readline().split()

        if command[0] == 'L':
            if left:
                right.appendleft(left.pop())
        elif command[0] == 'D':
            if right:
                left.append(right.popleft())
        elif command[0] == 'B':
            if left:
                left.pop()
        else:
            left.extend(command[1])

    left.extend(right)
    print(''.join(left))

solution()

https://www.acmicpc.net/problem/1406

Categories:

Updated:

Leave a comment