题目描述
在yxc大佬讲解基础上完整化。
C++ 代码
#include <iostream>
using namespace std;
const int N = 100010;
int stk[N], tt;
void push(int x)
{
stk[++ tt] = x;
}
void pop()
{
tt --;
}
int empty()
{
if(tt > 0) return 1;
else return 2;
}
int query()
{
printf("%d\n", stk[tt]) ;
}
int main()
{
int m;
cin >> m ;
while(m --)
{
string op;
int x;
cin >> op;
if(op == "push")
{
cin >> x;
push(x);
}
else if(op == "pop")
{
pop();
}
else if(op == "query")
{
query();
}
else
{
if(empty() == 1) printf("NO\n");
else printf("YES\n");
}
}
return 0;
}
hh