Team Queue(队列)

题目链接
*题意:t个队伍,每个队伍有n个人,两种操作:入队某个元素,出队。输出出队元素。
入队规则:如果该元素所在的队物在队列中,则插入该队伍最后,如果不存在,则插在所有队伍最后。

#include<bits/stdc++.h>
using namespace std ;
const int N = 1010 ;
int n ;
int ca ;
void solve(){
    queue<int>q[N] , tea;//每一个队的队内队列,队伍队列
    unordered_map<int,int>ma;//标记每一编号在属于哪个队
    for(int i = 1 ; i <= n ; i++){
        int t ; 
        scanf("%d" , &t);
        while(t--){
            int x ;
            scanf("%d" , &x);
            ma[x] = i;
        }
    }
    printf("Scenario #%d
" , ++ca);
    string str ;
    while(cin >> str && str[0] != 'S'){
        if(str[0] == 'E'){
            int x ;
            scanf("%d" , &x);
            int t = ma[x] ;
            if(q[t].size() == 0){
                tea.push(t);
            }
            q[t].push(x);
        }else{
            int t = tea.front() ; 
            int x = q[t].front() ; q[t].pop();
            if(q[t].size() == 0){
                tea.pop();
            }
            cout << x << endl;
        }
    }
    puts("");
}

int main(){
    while(~scanf("%d" , &n) && n){
        solve();
    }
}

原文地址:https://www.cnblogs.com/nonames/p/12652323.html