You are viewing a single comment's thread. Return to all comments →
Python
stack = [] def append(s, val): stack.append(s) s = s+val return s def delete(s, k): stack.append(s) s = s[:-k] return s def print_str(s, k): print(s[k]) def undo(): s = stack.pop() return s Q = int(input()) s = '' for _ in range(Q): operation = input().split() if operation[0] == '1': val = operation[1] s = append(s, val) elif operation[0] == '2': val = int(operation[1]) s = delete(s, val) elif operation[0] == '3': val = int(operation[1]) print_str(s, val-1) elif operation[0] == '4': s = undo()
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 →
Python