Lets Help Atom
All submissions for this problem are available.Atom is tired of using Notepad or Eclipse to code Java. He wants to create his own text editor.
Initially, Atoms editor contains an empty string S. He wishes his editor to perform following type of operations:
1. Append (W) – Appends string W to the end of S.
2. Delete (k) – Deletes the last k characters from S.
3. Print (k) – Prints the kth character of S.
4. Undo() – Undo the last operation (not previously undone operation) of type 1 or 2, reverting S to the state it was in prior to that operation.
Let’s help in creating Atoms Editor.
The first line contains an integer Q denoting the number of queries or operations.
Each line i of Q subsequent lines ($0 \leq i \lt Q$) defines an operation to be performed.
Each operation starts with a single integer t where (t will be 1,2,3 or 4) denoting the type of operation as defined in the question above.
If the operation requires an argument, t is followed by its space-separated argument.
For example, if t=1 and W=abcd, line will be 1 abcd.
- 1<=k<=|S| where |S| is the length of String S
- The sum of lengths of all W in the input <= 106
- All input characters are lowercase English letters.
- It is guaranteed that the sequence of operations given as input is possible to perform.
#### Output Format:
Each operation of type 3 must print the kth character on a new line.
#### Sample Input:
#### Sample Output:
Initially, S is empty. The following sequence of 8 operations are described below:
1. S= "". We append abc to S , so S = abc.
2. Print the 3rd character on a new line. Currently, the 3rd character is c.
3. Delete the last 3 characters in S(abc), so now S= "".
4. Append xy to S, so S= xy.
5. Print the 2nd character on a new line. Currently, the 2nd character is y.
6. Undo the last update to S, making S empty again (i.e., S= "").
7. Undo the next to last update to S (the deletion of the last 3 characters), making S= abc.
8. Print the 1st character on a new line. Currently, the 1st character is a.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions