• UVa540


    //先输入队伍的个数 
    //用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 输出的第二个

  • 相关阅读:
    一般操作
    node express mongodb 数据录入
    express新版本后app.use(express.bodyParser())无效
    npm adduser报错问题
    01demo-mongodb
    Win32汇编--02必须了解的基础知识
    第17章 本书最后将学习什么呢(需要回头学习)
    第十六章 直接定址表(需要回头学)
    指令系统总结
    第十五章 外中断
  • 原文地址:https://www.cnblogs.com/benzikun/p/10498839.html
Copyright © 2020-2023  润新知