Simple Text Editor

  • + 0 comments

    straightforward solution in python:

    intial_input = input().split(" ")
    n = int(intial_input[0])
    if len(intial_input) > 1:
        s = str(intial_input[1])
    else:
        s = ""
    undo = []
    for i in range(n):
        operation = input().split(" ")
        if operation[0] == '1':
            undo.append(s)
            s = s + (operation[1])
        elif operation[0] == '2':
            undo.append(s)
            x = len(s)
            s = s[0:x-int(operation[1])]
        elif operation[0] == '3':
            x = int(operation[1])-1
            print(s[x])
        elif operation[0] == '4':
            s = undo.pop()