首页 > 其他 > 详细

UVa540

时间:2019-03-09 00:16:20      阅读:328      评论:0      收藏:0      [点我收藏+]
//先输入队伍的个数 
//用map建立数组将队伍序号和个人序号相互对应 
//三条命令 

#include <bits/stdc++.h>
using namespace std;
const int maxn=1010;

int main()
{
    int t,kase=0;
    while(cin>>t && t)
  {
        cout<<"Scenario "<<"#"<<++kase<<endl;  
    
    map <int,int> team;
    for(int i=1;i<=t;i++)
    {
        int n,x;
        cin>>n;//队伍中人的个数 
        while(n--)
        {
            cin>>x;
            team[x]=i;//队员x在i(t)的队伍中 
        }
    }
    
    queue<int> q,q2[maxn];
    for(;;)
    {
        int x;
        string cmd;
        cin>>cmd;
        if(cmd[0]==S)//STOP命令,停止模拟 
        break;
        else if(cmd[0]==D)
        {
            int t=q.front();//第一个队伍的编号
            cout<<q2[t].front()<<endl;
            q2[t].pop();//输出并离队
            if(q2[t].empty())
            q.pop();//t队中的队员全部出队,移除队伍 
        }
        else if(cmd[0]==E)
        {
            cin>>x;
            int t=team[x];//队伍编号
            if(q2[t].empty())
            q.push(t);
            q2[t].push(x); 
        }
    }
    cout<<endl;
  }
return 0;
}

代码基本直接搬的紫书,初次接触了map和queue,简单写一下map和queue的使用笔记

queue的头文件是<queue>

基本操作有:

back()返回最后一个元素

empty()队列为空返回真

front()返回第一个元素

pop()删除第一个元素

push()在末尾加入一个元素

size()返回队列中的元素个数

此题定义了两个队列,第一个用来记录队伍,第二个用来记录对位内的成员

map当成了数组来用,头文件<map>

map的输出跟set挺像的

cout<<iter->first<<" "<<iter->second<<endl;

iter->first 输出的第一个 

iter->second 输出的第二个

 

UVa540

原文:https://www.cnblogs.com/benzikun/p/10498839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!