import sys
read = sys.stdin.readline
st1 = list(read().rstrip())
st2 = []
t = int(read().rstrip())
for _ in range(t):
arr = read().rstrip().split()
if arr[0] == 'L' and len(st1) > 0:
st2.append(st1[-1])
st1.pop()
elif arr[0] == 'D' and len(st2) > 0:
st1.append(st2[-1])
st2.pop()
elif arr[0] == 'B' and len(st1) > 0:
st1.pop()
elif arr[0] == 'P':
st1.append(arr[1])
print(''.join(st1) + ''.join(reversed(st2)))
리스트 문제를 이렇게 푸는건 또 처음이네..
'백준 1 > 자료구조' 카테고리의 다른 글
| [백준 6198] 옥상 정원 꾸미기 (C++/Python) (0) | 2023.06.14 |
|---|---|
| [백준 2493] 탑 (C++/Python) (0) | 2021.01.15 |
| [백준 2841] 외계인의 기타 연주 (C++/Java) (0) | 2020.12.06 |
| [백준 3986] 좋은 단어 (C++/Python) (0) | 2020.12.06 |
| [백준 1935] 후위 표기식2 (C++/Java) (0) | 2020.12.06 |