https://kbwplace.tistory.com/87
분의 설명을 보고 이해
왼쪽을 담당하는 스택1
오른쪽을 담당하는 스택2 를 만들어서
import sys
stack_left = list(sys.stdin.readline().rstrip())
stack_right = []
N = len(stack_left)
M = int(input())
for _ in range(M):
command = sys.stdin.readline().split()
if command[0] == "L" and stack_left:
stack_right.append(stack_left.pop())
elif command[0] == "D" and stack_right:
stack_left.append(stack_right.pop())
elif command[0] == "B" and stack_left:
stack_left.pop()
elif command[0] == "P":
stack_left.append(command[1])
print("".join(stack_left + list(reversed(stack_right))))
p는 커서
import sys
strr=list(input())
n=int(sys.stdin.readline())
cursor = len(strr)-1
totallen = n
for i in range(n):
inp=list(str(sys.stdin.readline().strip().split()))
if inp[2]=="D" and cursor<totallen:
cursor+=1
elif inp[2] =="B" and cursor>1:
totallen-=1
strr.pop(cursor)
cursor-=1
elif inp[2] =="L" and cursor>0:
cursor-=1
elif inp[2] =="P":
letter=inp[7]
strr.insert(cursor,letter)
print("".join(strr))