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