시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
0.3 초 (하단 참고) 128 MB 15101 3391 2280 25.199%

문제

한 줄로 된 간단한 에디터를 구현하려고 한다. 이 편집기는 영어 소문자만을 기록할 수 있는 편집기로, 최대 600,000글자까지 입력할 수 있다.

이 편집기에는 '커서'라는 것이 있는데, 커서는 문장의 맨 앞(첫 번째 문자의 왼쪽), 문장의 맨 뒤(마지막 문자의 오른쪽), 또는 문장 중간 임의의 곳(모든 연속된 두 문자 사이)에 위치할 수 있다. 즉 길이가 L인 문자열이 현재 편집기에 입력되어 있으면, 커서가 위치할 수 있는 곳은 L+1가지 경우가 있다.

이 편집기가 지원하는 명령어는 다음과 같다.

L 커서를 왼쪽으로 한 칸 옮김 (커서가 문장의 맨 앞이면 무시됨)
D 커서를 오른쪽으로 한 칸 옮김 (커서가 문장의 맨 뒤이면 무시됨)
B 커서 왼쪽에 있는 문자를 삭제함 (커서가 문장의 맨 앞이면 무시됨)
삭제로 인해 커서는 한 칸 왼쪽으로 이동한 것처럼 나타나지만, 실제로 커서의 오른쪽에 있던 문자는 그대로임
P \$ \$라는 문자를 커서 왼쪽에 추가함

초기에 편집기에 입력되어 있는 문자열이 주어지고, 그 이후 입력한 명령어가 차례로 주어졌을 때, 모든 명령어를 수행하고 난 후 편집기에 입력되어 있는 문자열을 구하는 프로그램을 작성하시오. 단, 명령어가 수행되기 전에 커서는 문장의 맨 뒤에 위치하고 있다고 한다.

입력

첫째 줄에는 초기에 편집기에 입력되어 있는 문자열이 주어진다. 이 문자열은 영어 소문자로만 이루어져 있으며, 길이는 100,000을 넘지 않는다. 둘째 줄에는 입력할 명령어의 개수를 나타내는 정수 N(1≤N≤500,000)이 주어진다. 셋째 줄부터 N개의 줄에 걸쳐 입력할 명령어가 순서대로 주어진다. 명령어는 위의 네 가지 중 하나의 형태로만 주어진다.

출력

첫째 줄에 모든 명령어를 수행하고 난 후 편집기에 입력되어 있는 문자열을 출력한다.

예제 입력 1

abcd
3
P x
L
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OLCAxICZsZTsgTiAmbGU7IDUwMCwwMDAsIG51bWJlciBvZiBnaXZlbiBvcGVyYXRpb25zLiZuYnNwOzxcL3A+XHJcblxyXG48cD5JbiB0aGUgbmV4dCBOIHJvd3MgdGhlcmUgYXJlIG9wZXJhdGlvbnMgZ2l2ZW4gaW4gdGhlIG9yZGVyIG9mIGV4ZWN1dGlvbi4mbmJzcDs8XC9wPlxyXG4iLCJvdXRwdXQiOiI8cD5JbiBmaXJzdCBhbmQgb25seSByb3cgeW91IHNob3VsZCB3cml0ZSB0ZXh0IGFmdGVyIHRoZSBleGVjdXRpb24gb2YgYWxsIHRoZSBvcGVyYXRpb25zLiZuYnNwOzxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2004 > National Competition #1 - Juniors 2번

  • 문제를 번역한 사람: author5
  • 데이터를 추가한 사람: djm03178
  • 시간 제한을 수정한 사람: jh05013
  • 어색한 표현을 찾은 사람: naong606
  • 문제의 오타를 찾은 사람: wkd48632

시간 제한 안내

아래 적혀있지 않은 시간 제한은 언어 도움말에 적혀있는 기준을 따른다.

  • Java: 2초
  • Java (OpenJDK): 2초
  • Kotlin: 2초