Simple Text Editor

  • + 0 comments

    My ansewr in python

    Q = int(input())
    S = str()
    prev = []
    
    operations = []
    for i in range(Q):
        operations.append(input().split(" "))
        
    for i, op in enumerate(operations):
        match op[0]:
            case "1":
                prev.append(S)
                S += op[1]
            case "2":
                prev.append(S)
                S = S[:-int(op[1])]
            case "3":
                print(S[int(op[1])-1])
            case "4":
                S = prev[-1]
                prev.pop()