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))
참고