#C12166. Taco Editor Operations
Taco Editor Operations
Taco Editor Operations
You are given a text editor that supports the following operations: APPEND
, DELETE
, PRINT
, UNDO
, and REDO
. Initially, the editor contains an empty string. The operations are performed in the order given via standard input. Specifically:
- APPEND "text": Append the given string (enclosed in quotes, either single or double) to the end of the current text.
- DELETE k: Delete the last \(k\) characters from the current text.
- PRINT k: Print the \(k^{th}\) character of the current text (1-indexed).
- UNDO: Revert the most recent operation that modified the text (
APPEND
orDELETE
). - REDO: Reapply the most recent operation that was undone.
Operations UNDO
and REDO
only apply to operations that change the editor's text. Your task is to process a sequence of operations and output the result of each PRINT
operation to standard output.
inputFormat
The first line contains an integer \(n\), the number of operations. Each of the next \(n\) lines contains an operation in one of the following formats:
APPEND "text"
DELETE k
PRINT k
UNDO
REDO
For the APPEND
operation, the text will be enclosed in either double quotes or single quotes. The value \(k\) is an integer.
outputFormat
For each PRINT
operation, output the corresponding character on a new line.
6
APPEND "abcde"
PRINT 3
DELETE 2
PRINT 3
UNDO
PRINT 4
c
c
d
</p>