#K58082. Text Editor with Undo Functionality

    ID: 30563 Type: Default 1000ms 256MiB

Text Editor with Undo Functionality

Text Editor with Undo Functionality

This problem requires you to simulate a text editor that supports basic operations with undo functionality. The editor starts with an empty string and supports the following commands:

  • append S: Append the string S to the current text.
  • delete k: Delete the last k characters from the current text.
  • print k: Print the k-th character (1-indexed) of the current text.
  • undo: Undo the most recent operation that modified the text (either append or delete).
  • exit: Terminate the command sequence.

When a modifying operation is executed, the editor saves its state so that it can be recovered using the undo command. For each print command, the specified character should be output on a new line.

The operations are to be processed sequentially until the exit command is encountered.

In case any mathematical expressions are needed, note that formulas should be provided in \( \LaTeX \) format.

inputFormat

The input is read from stdin and consists of multiple lines. Each line represents a command with one of the following formats:

  • append S — Append string S to the current text.
  • delete k — Delete the last k characters from the current text.
  • print k — Print the k-th character (1-indexed) of the current text.
  • undo — Undo the most recent append or delete command.
  • exit — End the input processing.

Commands are processed sequentially until an exit is encountered.

outputFormat

For each print command encountered in the input, output the corresponding character on a separate line to stdout.

## sample
append hello
append world
delete 5
print 5
undo
print 10
exit
o

d

</p>