Simple Editor
InterviewTime limit8sMemory limit1024 MB
Apply each keystroke in order (insert a lowercase letter left of the cursor, or move the cursor left or right) and print the final string for each dataset.
- Level
Easy3 of 10
- Topics
- Stack, Simulation, String
- Solved
- No attempts yet
Problem
You are a fairy who works inside a computer. Your job today is to operate an editor based on keyboard input.
You overslept! When you rush to your workplace, keyboard inputs have already piled up without being processed. What you must do now is display the string that results from processing all the pending inputs in order.
Let us review the situation. At first the editor holds no string, and there is only one vertical line (the cursor) that marks where characters are inserted.
Keyboard input comes in three kinds.
INSERTc: Insert the character c to the left of the cursor. More precisely, if no character is immediately to the left of the cursor, c goes at that position. If a character is there, c goes between that character and the cursor.LEFT _: Move the cursor one character to the left. If no character is to the left of the cursor, do nothing. The _ is a dummy that keeps the input format uniform.RIGHT _: Move the cursor one character to the right. If no character is to the right of the cursor, do nothing. The _ is a dummy that keeps the input format uniform.
Print the string after processing all pending inputs in order. You do not need to print the cursor.
Input
The input consists of multiple datasets. The number of datasets does not exceed 50. Each dataset has the following format.
N
a_1
⋮
a_N
The first line contains an integer , the number of keyboard inputs. It satisfies .
The next lines give the keyboard inputs in order. Each has one of the following forms.
INSERTc: c is a single lowercase English letter.LEFT _RIGHT _
It is guaranteed that at least one INSERT c input exists.
The input ends with a line containing a single zero.
Output
For each dataset, print on one line the string obtained after processing all keyboard inputs in order.