题解 | 【模板】队列操作
【模板】队列操作
https://www.nowcoder.com/practice/1137c8f6ffac4d5d94cc1b0cb08723f9
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
using namespace std;
int main() {
queue<int> q;
int n;
cin>>n;
while(n--)
{
char c;
cin>>c;
if(c=='1'){
int x;
cin>>x;
q.push(x);
}
else if (c=='2') {
if(!q.empty()){
q.pop();
}else cout<<"ERR_CANNOT_POP"<<endl;
}else if (c=='3') {
if(q.empty()){
cout<< "ERR_CANNOT_QUERY"<<endl;
}else cout<<q.front()<<endl;
}else {
cout<<q.size()<<endl;
}
}
return 0;
}
// 64 位输出请用 printf("%lld")
查看19道真题和解析