AcWing 829. 模拟队列
原题链接
简单
作者:
Avendator
,
2020-02-19 12:39:19
,
所有人可见
,
阅读 657
C++ 代码
# include <iostream>
using namespace std;
const int N = 100010;
int q[N], hh = 0, tt = -1;
void push(int x)
{
q[ ++tt ] = x;
}
void pop ()
{
hh ++;
}
string empty()
{
if (tt >= hh) return "NO";
else return "YES";
}
int query()
{
return q[hh];
}
int main()
{
int m;
cin >> m;
while (m --)
{
string op;
cin >> op;
if (op == "push")
{
int x;
cin >> x;
push(x);
}
else if (op == "pop")
{
pop();
}
else if (op == "empty")
{
string ans1;
ans1 = empty();
cout << ans1 << endl;
}
else if (op == "query")
{
int ans2;
ans2 = query();
cout << ans2 << endl;
}
}
return 0;
}