AcWing 828. 模拟栈
原题链接
简单
作者:
时过境迁
,
2021-02-02 16:38:16
,
所有人可见
,
阅读 315
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 100010;
int stack[N], top;
int m;
void push(int x)
{
top++;
stack[top] = x;
}
void pop()
{
top--;
}
bool empty()
{
return top == 0; //栈空是否成立
}
void query()
{
cout<<stack[top]<<endl;
}
int main()
{
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 == "empty")
{
if(empty())
puts("YES");
else
puts("NO");
}
else
{
query();
}
}
return 0;
}