目录
话不多说,直接上代码
代码:
#include <iostream>
#include <queue> //记得打上
using namespace std;
queue<int> q; //定义队列q
int main() {
int n;
cin >> n;
while (n--) {
int c;
cin >> c;
if (c == 1) { //将p加入队列q
int p;
cin >> p;
q.push(p);
} else if (c == 2) {
if (q.empty()) {
cout << "ERR_CANNOT_POP" << endl; //当队列为空输出
} else {
q.pop(); //否则弹出队首
}
} else if (c == 3) {
if (q.empty()) {
cout << "ERR_CANNOT_QUERY" << endl; //当队列为空输出
} else {
cout << q.front() << endl; //否则输出队首
}
} else {
cout << q.size() << endl; //输出队列长度
}
}
return 0;
}
AC:
总结:
模版题目,适合刚学习栈的做,思路还是很简单,主要考的是语法。