队列 + 分支语句
2023-08-06 17:30:14
发布于:上海
22阅读
0回复
0点赞
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
int n;
queue<int> Q;
queue<int> q[1006];
char ch[30];
int a[10000000];
int x;
int f;
int k = 1;
int main(void){
scanf("%d",&n);
{
memset(a,0,sizeof(a));
for(int i = 1;i <= 1005;++ i){
while(!q[i].empty())
q[i].pop();
}
while(!Q.empty())
Q.pop();
int hhh;
for(int i = 0;i < n;++ i){
scanf("%d",&hhh);
for(int j = 0;j < hhh;++ j){
scanf("%d",&x);
a[x] = i;
}
}
while(scanf("%s",&ch)){
if(ch[0] == 'S')
break;
if(ch[0] == 'E'){
scanf("%d",&x);
if(q[a[x]].empty()){
Q.push(x);
q[a[x]].push(x);
}
else{
q[a[x]].push(x);
}
}
if(ch[0] == 'D'){
printf("%d\n",q[a[Q.front()]].front());
q[a[Q.front()]].pop();
if(q[a[Q.front()]].empty())
Q.pop();
}
}
}
return 0;
}
这里空空如也
有帮助,赞一个