AcWing 829. 模拟队列
原题链接
简单
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int q[N];
int tt = 0, hh = 1;
void push(int x){
q[++tt] = x;
}
void pop(){
hh++;
}
void query(){
cout << q[hh] << endl;
}
bool empty(){
if(hh > tt) return true;
else return false;
}
int main(){
int m;
cin >> m;
for(int i = 0; i < m ;i++){
string str;
int x;
cin >> str;
if(str == "push"){
cin >> x;
push(x);
}
else if(str == "pop") pop();
else if(str == "empty"){
if(empty()) cout << "YES" << endl;
else cout << "NO" << endl;
}
else{
query();
}
}
return 0;
}