Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Python code Implement a simple text editor. The editor initially contains an empty string, S . Perform Q operations of the following 4 types: append

Python code
Implement a simple text editor. The editor initially contains an empty string, S.
Perform Q operations of the following 4 types:
append(W)- Append string W to the end of S.
delete(k)- Delete the last k characters of S.
print(k)- Print the kth character of S.
undo()- Undo the last (not previously undone) operation of type 1 or 2, reverting S to the state it was in prior to that operation.
Example
S= 'abcde'
ops=['1 fg','36','25','4','37','4','34']
operation
index S ops[index] explanation
--------------------------------
0 abcde 1 fg append fg
1 abcdefg 36 print the 6th letter - f
2 abcdefg 25 delete the last 5 letters
3 ab 4 undo the last operation, index 2
4 abcdefg 37 print the 7th characgter - g
5 abcdefg 4 undo the last operation, index 0
6 abcde 34 print the 4th character - d
The results should be printed as:
f
g
d
Input Format
The first line contains an integer, Q, denoting the number of operations.
Each line i of the Q subsequent lines (where 0<=i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions