AcWing 829. 模拟队列
原题链接
简单
作者:
SayYong
,
2024-09-24 15:56:55
,
所有人可见
,
阅读 1
#include <iostream>
#include <string>
using namespace std;
const int N = 100010;
int q[N];
int head = 0, tail = -1;
void push(int x) {
q[++tail] = x;
}
void pop() {
head++;
}
void empty() {
if (tail >= head) puts("NO");
else puts("YES");
}
void query() {
cout << q[head] << endl;
}
int main(void)
{
int m, x;
cin >> m;
while (m--) {
string str;
cin >> str;
if (str == "push") {
int x;
cin >> x;
push(x);
} else if (str == "pop") {
pop();
} else if (str == "empty") {
empty();
} else if (str == "query") {
query();
}
}
return 0;
}