AcWing 828. 模拟栈
原题链接
简单
作者:
Avendator
,
2020-02-19 12:19:38
,
所有人可见
,
阅读 739
C++ 代码
# include <iostream>
using namespace std;
const int N = 100010;
int stk[N], tt = 0;
void push(int x)
{
stk[ ++tt ] = x;
}
void pop ()
{
tt --;
}
string empty()
{
if (tt > 0)
return "NO";
else
return "YES";
}
int query()
{
return 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 == "empty")
{
string ans1;
ans1 = empty();
// printf(ans1);
cout << ans1 << endl;
}
else if (op == "query")
{
int ans2;
ans2 = query();
// printf(ans2);
cout << ans2 << endl;
}
}
}