#include<iostream>
#include<queue>
using namespace std;
void delect(queue<int>* q,int x){
if(q->empty()) return;
for(int i=0;i<q->size();i++){
int t=q->front();
q->pop();
if(t!=x) q->push(t);
}
}
int main(){
int n;
cin >> n;
queue<int> q;
queue<int> cat;
queue<int> dog;
for(int i=0;i<n;i++){
int x,y;
cin >> x >>y;
if(x==1){
q.push(y);
if(y>0){
dog.push(y);
}else{
cat.push(y);
}
}else if(x==2){
if(!q.empty()) {
if(y==0){
int t=q.front();
q.pop();
printf("%d ",t);
if(t>0){
delect(&dog,t);
}else{
delect(&cat,t);
}
}else if(y==1){
if(!dog.empty()){
int t=dog.front();
dog.pop();
printf("%d ",t);
delect(&q,t);
}
}else if(y==-1){
if(!cat.empty()){
int t=cat.front();
cat.pop();
printf("%d",t);
delect(&q,t);
}
}
}
}
}
return 0;
}
结果:
标签:delect,int,dog,C++,else,收容所,pop,cat From: https://www.cnblogs.com/llllmz/p/17971291