原题链接:
题解:
套板子即可
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int q[N], hh = 0, tt = -1;//分别代表队头的队尾
//向队尾插入一个元素
void push(int x) { q[++tt] = x; }
//从队头弹出一个数
void pop() { hh++; }
//判断队列是否为空
string empty() { return (hh <= tt) ? "NO" : "YES"; }
//查询队头元素
int query() { return q[hh]; }
int main() {
int M;cin >> M;
while (M--) {
string s;cin >> s;
int x;
if (s == "push") {
cin >> x;
push(x);
}
else if (s == "query")
cout << query() << endl;
else if (s == "pop")
pop();
else
cout << empty() << endl;
}
}