#59. 模拟栈

模拟栈

问题描述

你需要实现一个栈,初始时栈为空。有 mm 组查询,每次查询为以下四种操作之一:

  • push x:向栈顶插入一个正整数 xx。
  • pop:删除栈顶元素,若此时栈为空,则不做任何操作。
  • empty:判断栈是否为空,若为空输出 YES,否则输出 NO。
  • query:输出栈顶元素,若栈为空则输出 empty。

输入格式

第一行输入一个正整数 mm。(1≤m≤105)(1\le m\le 10^5)

接下来 mm 行,每行输入一种操作,对于 empty 与 query,需要有对应的输出。push x 的 xx 范围 (1≤x≤105)( 1\le x\le 10^5)。

输出格式

对于 empty 与 query 操作,按照题目要求输出。

样例输入

10
push 5
query
push 6
pop
query
pop
empty
push 4
query
empty

样例输出

5
5
YES
4
NO