您的位置:首页 > 产品设计 > UI/UE

uva 540 Team Queue(queue与STL其他容器的综合运用)

2016-09-28 16:19 423 查看
题目链接:here

思路还是很简单的,,用map[a][i]  表示编号为a 的人在i的队伍里面,然后用队列表示每个队伍;

#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
const int maxn = 1000+10;

int main(){
int t;
int x=1;
//freopen("0.txt","r",stdin);
while(~scanf("%d",&t)&&t)
{
printf("Scenario #%d\n",x++);
map<int,int> team;
for(int i=1;i<=t;i++){
int n;
scanf("%d",&n);
while(n--){
int a;
scanf("%d",&a);
team[a]=i;
}
}
queue<int> q,q2[maxn];
string s;
while(cin>>s)
{
if(s[0]=='S') break;
else if(s[0]=='E'){
int a;
scanf("%d",&a);
int t=team[a];
if(q2[t].empty()) q.push(t);
q2[t].push(a);

}else if(s[0]=='D'){
int t=q.front();
cout<<q2[t].front()<<endl;;
q2[t].pop();
if(q2[t].empty()) q.pop();
}
}
printf("\n");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva 540 Team Queue