团队队列

#include<cstdio> #include<iostream> #include<map> #include<queue> using namespace std; int main(void) { int kcase = 0; int n;//有多少队伍 while (scanf("%d", &n)&&n) { printf("Scenario #%d\n", ++kcase); //通过map将每一个队伍的编号映射出来,每次询问队友号都能找到队伍号 //================保存队伍 map<int, int > mp; for (int i = 0; i < n; i++) { int h; cin >> h;//每一个队伍的人数 for (int j = 0; j < h; j++) { int a; cin >> a; mp[a] = i; } } //=================保存队伍结束 //==============执行命令 queue<int> q, q2[1010];//第一个队列记录队伍进入的顺序,第二个队列记录每个队伍的队员进入顺序 while (1) { char cmd[10]; scanf("%s", cmd); if (cmd[0] == 'S') break; if (cmd[0] == 'E') { int x; cin >> x; int t = mp[x];//记录每个要进入队员的队伍号 if (q2[t].empty()) q.push(t);//如果t号队伍里面没有进入过,那么就跟在另一个队伍后面 q2[t].push(x); } if (cmd[0] == 'D') { int t = q.front(); printf("%d\n", q2[t].front()); q2[t].pop(); if (q2[t].empty()) q.pop(); } } //====================命令结束 cout << endl; } return 0; }
计算机小白记录学习过程,喜欢就点个推荐和关注吧O(∩_∩)O哈哈~

浙公网安备 33010602011771号