SHyeonL / Future_Internet_LAB_Algorithm

미래 인터넷 연구실 알고리즘 스터디
0 stars 0 forks source link

1406 - 에디터 #8

Open SHyeonL opened 1 year ago

SHyeonL commented 1 year ago
import sys

input = sys.stdin.readline

left_stk = list(input().strip())
right_stk = []
m = int(input())

for i in range(m):
    a = list(input().split())
    if a[0] == 'L':
        if left_stk:
            right_stk.append(left_stk.pop())
    if a[0] == 'D':
        if right_stk:
            left_stk.append(right_stk.pop())
    if a[0] == 'B':
        if left_stk:
            left_stk.pop()
    if a[0] == 'P':
        left_stk.append(a[1])

left_stk.extend(reversed(right_stk))
print(''.join(left_stk))

# 리스트를 역순으로 reversed()
# 리스트 합치기 extend
# 리스트 요소를 문자열로 바꾸기 .join()
yuneojin commented 1 year ago
from sys import stdin

left = list(input())
right = []

for i in range(int(input())):
    command = stdin.readline().split()
    if command[0] == 'P':
        left.append(command[1])

    elif command[0] == 'L' and left:
        right.append(left.pop())

    elif command[0] == 'D' and right:
        left.append(right.pop())

    elif command[0] =='B' and left:
        left.pop()

answer = left + right[::-1]

print(''.join(answer))