题目来源:
https://www.acwing.com/problem/content/831/
#include<iostream>
#include<cstdio>
using namespace std;
int q[100010];
int head,tail;//头尾指针
void push(int x)
{
q[tail++]=x;
}
void pop()
{
head++;
}
void empty()
{
if(head>=tail)
{
cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;
}
int query()
{
return q[head];
}
int main()
{
int m;
cin>>m;
while(m--)
{
int x;
string c;
cin>>c;
if(c=="push")
{
cin>>x;
push(x);
}
else if(c=="pop")
{
pop();
}
else if(c=="empty")
{
empty();
}
else
{
int result=query();
printf("%d\n",result);
}
}
}