AcWing 828. 模拟栈
原题链接
简单
作者:
dsyami
,
2021-05-11 12:04:35
,
所有人可见
,
阅读 164
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int stack[N], tt = -1;
void push(int x)
{
stack[++ tt] = x;
}
void pop()
{
tt -- ;
}
bool empty()
{
if(tt < 0) return 1;
else return 0;
}
int query()
{
return stack[tt];
}
int main()
{
int m, x;
string op;
cin >> m;
while(m -- )
{
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 if(op == "query")
cout << query() << endl;
}
return 0;
}