Stack · Compiler
Stack
Process an editor's undo history, starting with an empty stack. PUSH x records change x at the top. UNDO removes and reports the most recently recorded change still on the stack. An UNDO on an empty stack reports EMPTY.
- Input
- The first line contains the command count q (1 <= q <= 100). Each of the next q lines contains PUSH x or UNDO. Each x is an integer from 1 to 1000. There is at least one UNDO.
- Output
- Print one line per UNDO, containing the removed ID or EMPTY.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…