Drafting Cover Letter
Brooke is applying to the extremely prestigious, definitely real, and slightly intimidating megacorporation AUCPL Inc. As part of the application process, she must type her crazily good, hire-me-immediately cover letter directly into the company's online application platform
The platform text editor works by receiving sequences of actions from Brooke's computer, including:
- typing text at the current cursor position
- moving the cursor to the left or to the right by using arrow keys
- deleting some characters by using backspace
The cursor starts at the beginning of an empty response field. It cannot move before the start of the text or beyond the end of the current content.
Given the sequence of Brooke's actions, determine the final content of her cover letter.
Input
The first line contains an integer (
), the number of Brooke's actions.
The next lines each contains an action. These lines will take the form
ADD text (,
text only consists of English letters), DEL k, LEFT k, RIGHT k ().
ADD text: addtextto the current cursor position. The cursor will then move to the end of the inserted text.DEL k: delete at mostkcharacters immediately to the left of the cursor (Brooke uses backspace k times)LEFT k: move the cursorktimes to the left (aka Brooke uses left arrows k times). If the cursor cannot move left any further at any point, it should stop at the earliest possible position.RIGHT k: move the cursorktimes to the right (aka Brooke uses right arrows k times) If the cursor cannot move right any further at any point, it should stop at the latest possible position.
Output
A string represents the final cover letter content that AUCPL Inc will receive.
Example
Input 1
3
ADD DearAUCPL
DEL 5
ADD ACPC
Output 1
DearACPC
Command and resulting text:
Starting text -> "|" (The '|' character represents the cursor)
ADD DearAUCPL -> "DearAUCPL|"
DEL 5 -> "Dear|"
ADD ACPC -> "DearACPC|"
Input 2
9
ADD WillYou
ADD HireMeeeee
DEL 4
LEFT 50
ADD ACPCInc
RIGHT 7
ADD Please
RIGHT 50
ADD Thanks
Output 2
ACPCIncWillYouPleaseHireMeThanks
Command and resulting text:
Starting text -> "|" (The '|' character represents the cursor)
ADD WillYou -> "WillYou|"
ADD HireMeeeee -> "WillYouHireMeeeee|"
DEL 4 -> "WillYouHireMe|"
LEFT 50 -> "|WillYouHireMe" (The cursor cannot go beyound the starting point)
ADD ACPCInc -> "ACPCInc|WillYouHireMe"
RIGHT 7 -> "ACPCIncWillYou|HireMe"
ADD Please -> "ACPCIncWillYouPlease|HireMe"
RIGHT 50 -> "ACPCIncWillYouPleaseHireMe|" (The cursor cannot go beyound current text)
ADD Thanks -> "ACPCIncWillYouPleaseHireMeThanks|"
Comments