码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 540 Team Queue

时间:2019-02-07 21:58:07      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:char   bre   --   int   print   team   break   span   ace   

 1 #include "cstdio"
 2 #include "queue"
 3 #include "map"
 4 using namespace std;
 5 int main()
 6 {
 7     int t,kase=0;//t团队数目
 8     while (scanf("%d",&t)==1&&t)
 9     {
10         printf("Scenario #%d\n", ++kase);
11         map<int, int> team;//记录所有人团队编号
12         //<元素x,团队编号>
13         //team[x]为元素x所在团队的编号
14         for (int i = 0; i < t; i++)
15         {
16             int n;//每个团队的元素个数
17             scanf("%d", &n);
18             while (n--)
19             {
20                 int x;
21                 scanf("%d", &x);
22                 team[x] = i;
23             }
24         }
25         queue<int> q, q2[1010];
26         while (true)
27         {
28             char cmd[10];
29             scanf("%s", cmd);
30             if (cmd[0] == S)//STOP
31                 break;
32             else if (cmd[0] == D)//队首出队
33             {
34                 int t = q.front();
35                 printf("%d\n", q2[t].front());
36                 q2[t].pop();
37                 if (q2[t].empty())
38                     q.pop();//团队t全部出队
39             }
40             else if (cmd[0] == E)//入队
41             {
42                 int x;
43                 scanf("%d", &x);
44                 int t = team[x];
45                 if (q2[t].empty())//为空加入q
46                     q.push(t);
47                 q2[t].push(x);
48             }
49         }
50         printf("\n");
51     }
52     return 0;
53 }

 

UVA 540 Team Queue

标签:char   bre   --   int   print   team   break   span   ace   

原文地址:https://www.cnblogs.com/fudanxi/p/10355519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!