[ds] 백준 #1406 에디터
문제
https://www.acmicpc.net/problem/1406
풀이
# 에디터
import sys
from collections import deque
input = sys.stdin.readline
left = deque(input())
right = deque()
m = int(input())
left.pop()
for _ in range(m):
op = list(map(str, input().split()))
if op[0] == 'P':
left.append(op[1])
elif op[0] == 'L':
if left:
right.appendleft(left.pop())
elif op[0] == 'D':
if right:
left.append(right.popleft())
else:
if left:
left.pop()
print(left, right)
print(''.join(left)+''.join(right))
접근
커서를 직접 움직이는게 아니라 두개의 deque를 사용해서 커서를 기준으로 문자를 왼쪽 deque와 오른쪽 deque로 이동시킨다.
Author And Source
이 문제에 관하여([ds] 백준 #1406 에디터), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@zio_oii/ds-백준-1406-에디터저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)