829. 模拟队列
#include<iostream>
using namespace std;
const int N = 100010;
int q[N], hh, tt = -1;
void push(int x){
q[ ++ tt] = x;
}
void pop(){
hh++;
}
void empty(){
if(hh <= tt)cout << "NO" << endl;
else cout << "YES" << endl;
}
void query(){
cout << q[hh] << endl;
}
int main(){
int m ,x;
string op;
cin >> m;
while(m --){
cin >> op;
if(op == "push"){
cin >> x;
push(x);
}else if(op == "query"){
query();
}else if(op == "pop"){
pop();
}else{
empty();
}
}
return 0;
}
评论区