AcWing 829. 模拟队列
原题链接
简单
作者:
术
,
2021-01-05 20:29:17
,
所有人可见
,
阅读 275
#include <iostream>
using namespace std;
const int N=100005;
int qu[N];
int hh=0,tt=-1;
void push(int x){
qu[++tt]=x;
}
void pop(){
hh++;
}
bool empty(){
return !(hh-tt-1);
}
int query(){
return qu[hh];
}
int main()
{
int m,x;
string s;
cin>>m;
while(m--){
cin>>s;
if(s=="push")cin>>x,push(x);
else if(s=="pop") pop();
else if(s=="empty") empty()?cout<<"YES"<<endl:cout<<"NO"<<endl;
else cout<<query()<<endl;
}
//cout << "Hello world!" << endl;
return 0;
}