Algorithm/백준

백준 1406 파이썬 에디터

researcher 틴틴 2025. 3. 26. 11:52

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

 

 

 

리스트 2개 만들기

오른쪽 리스트는 뒤집어서 붙여주기

 

 

 

from sys import stdin
left = list(input())
right = []

for _ in range(int(input())):
    command = list(stdin.readline().split())
    if 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()
    elif command[0] == 'P' :
        left.append(command[1])

    answer = left + right[::-1]
    print(''.join(answer))


 

 

 

 

참고

https://corin-e.tistory.com/entry/%EB%B0%B1%EC%A4%80-1406-%EC%97%90%EB%94%94%ED%84%B0-%ED%8C%8C%EC%9D%B4%EC%8D%AC