#K79267. Taco Text Editor
Taco Text Editor
Taco Text Editor
You are required to implement a simple text editor that supports basic operations: inserting a character at the current cursor location, moving the cursor one position to the left, and moving it one position to the right.
The text editor initially contains an empty string. The operations are processed sequentially, and the final state of the text is output when the "get_text" command is encountered.
Operations:
insert c
: Insert character c at the current cursor position.move_left
: Move the cursor one position to the left. If the cursor is at the beginning, do nothing.move_right
: Move the cursor one position to the right. If the cursor is at the end, do nothing.get_text
: Output the final text and terminate processing.
Note: Internally, an efficient way to implement the text editor is to use two stacks. Mathematically, if the left stack contains characters before the cursor and the right stack contains characters after the cursor, then the final text can be computed as:
\( \text{result} = \text{left}\, + \text{reverse}(\text{right}) \)
inputFormat
The first line of the input contains an integer \(N\) which denotes the total number of operations. The next \(N\) lines each contain one of the following commands:
insert c
where c is a single character.move_left
move_right
get_text
It is guaranteed that there will be exactly one get_text
command that terminates the operations.
outputFormat
Output a single line containing the final text in the editor after processing all operations.
## sample6
insert a
insert b
insert c
move_left
insert d
get_text
abdc