运用queue解决本题的题解
2025-08-25 13:04:55
发布于:浙江
0阅读
0回复
0点赞
运用queue解决代码:
#include <iostream>
#include <queue>
using namespace std;
int main() {
int n;
cin >> n;
queue<int> q;
while (n--) {
int op;
cin >> op;
if (op == 1) {
int x;
cin >> x;
q.push(x);
}
else if (op == 2) {
if (q.empty()) {
cout << "impossible!" << endl;
}
else {
q.pop();
}
}
else if (op == 3) {
if (q.empty()) {
cout << "impossible!" << endl;
}
else {
cout << q.front() << endl;
}
}
}
return 0;
}
这里空空如也
有帮助,赞一个