My Notepad

3.6

11 votes
Problem

Students of Computer Science Department of SKIT have designed a basic Notepad for the purpose of studying the functioning and advance features in many other text editors. It is a simple text editor that supports only the following two commands:

"type c" where c is a character: Append character c to the end of the current text.

"undo t" where t is an integer: Undo all operations that were performed in the previous t seconds in reverse order.

Note :

  • All quotes are for clarity only.
  • The text in the editor is initially empty.
  • "undo" commands can also be undone.

Input :

The first line of the input contains an integer T representing the number of test cases.

Each test case starts with an integer N representing the total number of commands in the test case. Now, N lines of input follows, each line containing exactly three space separated entities

  • S type c where S is time of command (in sec.) and c is the character to be typed.
  • or S undo t where S is time of command (in sec.) and t is the time (in sec.) as explained above.

Output :

Print the resulting text after executing all the commands in a single line for each test case.

Constraints :

  • 30 <= T <= 150
  • 1 <= N <= 50
  • 1 <= S, t <= 10^9
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Case #1:

The commands are as

Second 1: type a

Second 2: type b

Second 3: type c

Second 5: undo 3

After second 2, the text is "ab". After second 3, everything is undone, and the text becomes empty. At second 4, the previous "undo" is undone, so the text becomes "ab" again. Then, the "type b" is also undone and the text becomes just "a".

Case #2:

At the end of second 3, the text is "abc". At second 5, all commands performed in the previous 3 seconds are undone in reverse order. This means 'c' is removed, and then 'b' is removed. The text becomes just "a"

Editor Image

?