Today
Total
04-09 14:23
관리 메뉴

홍우진의 개발 일기장

[백준] 1406번: 에디터 / 파이썬 본문

알고리즘/백준

[백준] 1406번: 에디터 / 파이썬

홍우진 2025. 3. 4. 23:55
728x90
반응형

문제 링크


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

풀이 코드


from sys import stdin

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

for _ in range(int(input())):
    inp = list(stdin.readline().split())
    if inp[0] == 'L' and left:
        right.append(left.pop())
    elif inp[0] == 'D' and right:
        left.append(right.pop())
    elif inp[0] == 'B' and left:
        left.pop()
    elif inp[0] == 'P':
        left.append(inp[1])

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

코드 해석


 리스트를 왼쪽과 오른쪽, 두개를 만들면 편하다.

커서가 움직일 때, 값을 왼쪽과 오른쪽 리스트로 움직이면 된다.

대신 오른쪽 리스트는 뒤집어진 상태임을 염두에 두어야 한다.

 

체감 난이도: ★★☆☆

728x90
반응형
Comments