Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t,kase=0,n,e,x;
- string s;
- while(cin>>t)
- {
- map<int,int>mp,mp2;
- if(t==0) break;
- vector<int>v[t+1];
- for(int i=0; i<t; i++)
- {
- cin>>e;
- for(int j=0; j<e; j++)
- {
- cin>>x;
- v[i].push_back(x);
- mp[x]=i;
- }
- }
- queue<int>q[t+1];
- queue<int>q2;
- cout<<"Scenario #"<<++kase<<endl;
- while(cin>>s)
- {
- if(s=="STOP") break;
- else if(s=="ENQUEUE")
- {
- cin>>x;
- int y=mp[x];
- if (q[y].empty())
- {
- q2.push(y);
- }
- q[y].push(x);
- }
- else
- {
- int y=q2.front();
- cout<<q[y].front()<<endl;
- q[y].pop();
- if(q[y].empty())
- q2.pop();
- }
- }
- cout<<endl;
- }
- cout<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment