前言:
这道题因为定义queue定了全局wa了一下午…
思路:
定义一个队列,然后模拟操作
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
using namespace std;
int n,m,k,xh;
int jl[10000001];
string s;
int main()
{
cin>>n;
while(n!=0)//n永不停留
{
queue<int>h[1001];
xh++;//序号++
cout<<"Scenario #"<<xh<<endl;
for(int i = 1;i <= n;i++)
{
cin>>m;
for(int j = 1;j <= m;j++)
{
cin>>k;
jl[k] = i;//记录一下
}
}
cin>>s;
while(s != "STOP")
{
if(s =="ENQUEUE")//插入
{
cin>>m;
if(!h[jl[m]].size())
h[0].push( jl[m] );
h[jl[m]].push( m );
}
else if(s == "DEQUEUE")//查询
{
m=h[0].front();
k=h[m].front();
h[m].pop();
if(!h[m].size())
h[0].pop();
cout<<k<<endl;
}
cin>>s;
}
cout<<endl;
cin>>n;
}
return 0;
}