cswork / OA打开练习工作台

MicrosoftOA #31

Implement Queue using Stacks (Round 2, LC 232

估计简单可在线判题

考点(AI 标注)迭代器设计单调栈与堆

The queue starts empty. Implement push, pop, peek, and empty using only two stacks. Output the return value of every operation, with null for push; this site does not output anything for the constructor. The judge checks behavior only, so please respect the two-stack restriction in your implementation.

输入格式

The first line contains the number of operations Q (1..100), followed by Q lines: push x (1..9), pop, peek, or empty. The queue is guaranteed to be non-empty for pop and peek.

输出格式

Output the Q return values on one line, separated by spaces, using null, true, false, or integers.

样例 1

输入:

5
push 1
push 2
peek
pop
empty

输出:

null null 1 1 false

样例 2

输入:

1
empty

输出:

true

样例 3

输入:

3
push 9
pop
empty

输出:

null 9 true

样例说明

Example 1: the return values are null, null, 1, 1, false in order, and 2 remains in the queue at the end.

Example 2: the queue starts empty, so it returns true.

Example 3: 9 is enqueued and then removed, leaving the queue empty; the return values are null, 9, true.