juyana

uva 540

Jan 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t,kase=0,n,e,x;
  8. string s;
  9. while(cin>>t)
  10. {
  11. map<int,int>mp,mp2;
  12. if(t==0) break;
  13. vector<int>v[t+1];
  14. for(int i=0; i<t; i++)
  15. {
  16. cin>>e;
  17. for(int j=0; j<e; j++)
  18. {
  19. cin>>x;
  20. v[i].push_back(x);
  21. mp[x]=i;
  22. }
  23. }
  24. queue<int>q[t+1];
  25. queue<int>q2;
  26. cout<<"Scenario #"<<++kase<<endl;
  27. while(cin>>s)
  28. {
  29. if(s=="STOP") break;
  30. else if(s=="ENQUEUE")
  31. {
  32. cin>>x;
  33. int y=mp[x];
  34. if (q[y].empty())
  35. {
  36. q2.push(y);
  37. }
  38.  
  39. q[y].push(x);
  40. }
  41.  
  42. else
  43. {
  44. int y=q2.front();
  45. cout<<q[y].front()<<endl;
  46. q[y].pop();
  47. if(q[y].empty())
  48. q2.pop();
  49.  
  50. }
  51. }
  52. cout<<endl;
  53. }
  54. cout<< endl;
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment