UVA 540 Team 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 }
标签:q2,int,scanf,cmd,Queue,540,team,UVA,include 来源: https://www.cnblogs.com/fudanxi/p/10355519.html