#K86107. Text Editor Simulation

    ID: 36791 Type: Default 1000ms 256MiB

Text Editor Simulation

Text Editor Simulation

You are given a series of operations to simulate a text editor. The editor supports two primary operations: APPEND and UNDO. The APPEND operation appends the provided string to the current text, while the UNDO operation reverts the text to its state before the last APPEND operation. Additionally, the command PRINT will output the current content of the text.

More formally, let the current text be represented by ( T ). When an operation APPEND X is encountered, the current state of ( T ) is saved, and then the string ( X ) is concatenated to ( T ). The UNDO operation reverts ( T ) to its previous state if one exists. Upon receiving the PRINT command, the final state of ( T ) is output. Input and output are handled via stdin and stdout respectively.

inputFormat

The input is read from standard input. The first line contains an integer ( n ), the number of operations. Each of the next ( n ) lines contains one operation. An operation can be one of the following: APPEND <text>, UNDO, or PRINT.

outputFormat

When a PRINT operation is encountered, the current text is output to standard output. For each test case, it is guaranteed that the PRINT command appears exactly once, at the end of the sequence.## sample

2
APPEND Hello
PRINT
Hello