#K49382. Taco Text Editor Undo Simulation
Taco Text Editor Undo Simulation
Taco Text Editor Undo Simulation
You are given a simulated text editor which supports three types of operations:
append <string>
: Append the given string at the end of the current text.delete k
: Delete the last k characters from the current text.undo
: Revert the lastappend
ordelete
operation.
For every undo
operation that reverts an append
operation, you must print the current state of the text (after the undo) to stdout. Note that undoing a delete
operation does not produce any output.
The operations are provided as input, and you should process them in order. The input starts with an integer n representing the number of operations, followed by n lines each containing one operation.
Note: The internal implementation of the undo operation should restore the text to its previous state correctly. Make sure to consider edge cases where there are no operations to undo.
inputFormat
The first line contains an integer n (1 ≤ n ≤ 105), the number of operations.
Each of the following n lines contains one operation. Each operation is one of the following:
append <string>
delete k
where k is an integer.undo
Operations are given in order and should be processed sequentially from the first to the last.
outputFormat
For every undo
operation that reverts an append
operation, output the current state of the text on a new line. If an undo reverts a delete
operation, do not print anything.
7
append hello
append world
delete 5
append !
undo
append .
undo
hello
hello
</p>