https://www.acmicpc.net/problem/1406
스택을 응용하게된 새로운 경험!
앞으로 다른사람의 풀이도 확인해보고 배우자!
import sys
line = sys.stdin.readline().rstrip()
N = int(sys.stdin.readline().rstrip())
l_stack = list(line)
r_stack = []
for i in range(N):
cmd = sys.stdin.readline().rstrip().split()
if "L" in cmd and l_stack: # 왼쪽으로 한칸
r_stack.append(l_stack.pop())
elif"D" in cmd and r_stack: # 오른쪽으르 한칸
l_stack.append(r_stack.pop())
elif "B" in cmd and l_stack: # 왼쪽문자 삭제
l_stack.pop()
else: # 왼쪽에 문자 추가
if "P" in cmd:
l_stack.append(cmd[1])
print(''.join(l_stack+r_stack[::-1]))
import sys
n = sys.stdin.readline().rstrip()
b = int(sys.stdin.readline())
l_stack = list(n)
r_stack = []
for s in range(b):
x = sys.stdin.readline().rstrip()
if x == "L" and l_stack:
r_stack.append(l_stack.pop())
elif x == "D" and r_stack:
l_stack.append(r_stack.pop())
elif x == "B" and l_stack:
l_stack.pop()
else:
if x[0] == "P":
l_stack.append(x[2])
print(''.join(l_stack + r_stack[::-1]))