#P12281. Enhanced Text Editor Simulation
Enhanced Text Editor Simulation
Enhanced Text Editor Simulation
Initially, the text file is empty. The enhanced text editor supports a set of commands to manipulate the text. The commands are as follows:
Command | Function |
---|---|
[n]h | Move the cursor left by \(n\) characters (stop at the beginning). |
[n]l | Move the cursor right by \(n\) characters (stop at the end). |
insert "[text]" | Insert the given [text] at the current cursor position and move the cursor to the right end of the inserted text. |
d [n]h | Delete \(n\) characters to the left of the cursor (if fewer than \(n\) exist, delete all). |
d [n]l | Delete \(n\) characters to the right of the cursor (if fewer than \(n\) exist, delete all). |
You are given a series of commands to be executed sequentially. After processing all the commands, output the final text content.
inputFormat
The first line contains an integer T, the number of commands. Each of the following T lines contains one command. The commands can be of the following forms:
- [n]h
- [n]l
- insert "[text]"
- d [n]h
- d [n]l
Note: (n) is a positive integer and [text] denotes the string to be inserted.
outputFormat
Output the final text after all commands are executed.
sample
1
insert "hello"
hello