UVA 540 Team Queue

本文介绍了一个使用C++实现的团队竞赛模拟程序。程序通过读取输入数据,模拟多个团队的竞赛过程,包括团队成员的入队和出队操作。采用map和queue数据结构来跟踪每个团队的状态,实现了竞赛的动态更新。
 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 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值