AcWing 829. 模拟队列


#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int q[N],hh,tt;
void init(){
    hh=0;
    tt=-1;
}
void add(int x){
    q[++tt]=x;
}
void remove(){
    hh++;
}
int main(){
    int m;
    cin>>m;
    init();
    while(m--){
        string op;
        cin>>op;
        int x;
        if(op=="push"){
            scanf("%d",&x);
            add(x);
        }else if(op=="pop"){
            remove();
        }else if(op=="empty"){
            if(hh>tt) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }else if(op=="query"){
            cout<<q[hh]<<endl;
        }
    }
    return 0;
}