AcWing 829. 模拟队列
原题链接
简单
作者:
刘杰
,
2024-01-09 13:42:35
,
所有人可见
,
阅读 58
#include <iostream>
using namespace std;
const int N =1e5+10;
int m;
int q[N], hh, tt = -1;
void push(int x){
q[++tt] = x;
}
int pop(){
return q[hh++];
}
bool isEmpty(){
return hh <= tt;
}
int query(){
return q[hh];
}
int main(){
cin >> m;
while(m--){
string op;
int x;
cin >> op;
if(op == "push"){
cin >> x;
push(x);
}
else if(op == "pop"){
pop();
}
else if(op == "empty") cout << (isEmpty() ? "NO": "YES") << endl;
else cout << query() << endl;
}
return 0;
}