You are viewing a single comment's thread. Return to all comments →
n_q=int(input()) undo_stack=[] s="" def perform(op, param, in_undo=False): global s match op: case 'append': if not in_undo: undo_stack.append(('delete', len(param))) s+= param case 'delete': if not in_undo: undo_stack.append(('append', s[len(s)-int(param):])) s = s[0:len(s)-int(param)] case 'print': print(s[int(param)-1]) case 'undo': un_op, un_param = undo_stack.pop() perform(un_op, un_param, in_undo=True) ops=['ops','append','delete','print','undo'] for _ in range(n_q): q=input().split() op=ops[int(q[0])] param = None if op!='undo': param=q[1] #now, perform perform(op, param)
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Text Editor
You are viewing a single comment's thread. Return to all comments →