Simple Text Editor

  • + 0 comments

    Python 3:

    q = int(input())
    
    s = ''
    revert = [s]
    
    for _ in range(q):
        line = input().strip().split()
        operation = int(line[0])
        try:
            argument = line[1]
        except Exception:
            pass
            
        match operation:
            case 1:
                revert.append(s)
                s += argument
            case 2:
                revert.append(s)
                for _ in range(int(argument)):
                    s = s[:-1]
            case 3:
                print(s[int(argument)-1])
            case 4:
                s = revert.pop()