AcWing 829. 模拟队列
原题链接
简单
作者:
自律
,
2021-07-17 17:39:41
,
所有人可见
,
阅读 233
#include<iostream>
#include<string>
using namespace std;
const int N = 1e5 + 10;
int q[N];
int tail,head;
void init() //初始化
{
head = -1;
tail = -1;
}
void push(int x)
{
q[++tail] = x;
}
void pop()
{
head++;
}
void empty()
{
if(head < tail) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
void query()
{
cout<<q[head + 1]<<endl;
}
int main()
{
init();
int m;
string s;
cin>>m;
while(m--)
{
cin>>s;
if(s == "push")
{
int x;
cin>>x;
push(x);
}
else if(s == "pop") pop();
else if(s == "empty") empty();
else query();
}
return 0;
}