Team Queue(UVa 540)

版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/86745180

#include <iostream>
#include <bits/stdc++.h>
#define maxn 1010
using namespace std;

int main()
{
    int k,kase = 1;
    while(cin>>k&&k)
    {
        cout<<"Scenario #"<<kase++<<endl;
        //对应队号
        map<int,int>team;
        for(int i = 0;i<k;i++)
        {
            int num,x;
            cin>>num;
            for(int j = 0;j<num;j++)
            {
                cin>>x;
                team[x] = i;
            }
        }
        //模拟
        queue<int>q,q2[maxn];
        string t;
        int x;
        while(cin>>t&&t!="STOP")
        {
            //cout<<"hhh"<<endl;
            if(t[0]=='E')
            {
                cin>>x;
                int qnum = team[x];
                if(q2[qnum].empty())
                {
                    q.push(qnum);
                }
                q2[qnum].push(x);
            }
            if(t[0]=='D')
            {
                int a,b;
                a = q.front();
                cout<<q2[a].front()<<endl;
                q2[a].pop();
                if(q2[a].empty())
                    q.pop();
            }
        }
        cout<<endl;
    }
    return 0;
}
/**
2
3 101 102 103
3 201 202 203
ENQUEUE 101
ENQUEUE 201
ENQUEUE 102
ENQUEUE 202
ENQUEUE 103
ENQUEUE 203
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
**/
 

猜你喜欢

转载自blog.csdn.net/qq_36257146/article/details/86745180