首页 > 其他分享 >UVA540 Team Queue 队列入门经典

UVA540 Team Queue 队列入门经典

时间:2023-02-07 17:02:30浏览次数:56  
标签:q2 int DEQUEUE Queue ENQUEUE Team UVA540 include op


题意翻译

有t个团队的人正在排一个长队。每次新来一个人时,如果他有队友在排队,那么新人会插队到最后一个队友的身后。如果没有任何一个队友排队,则他会被排到长队的队尾。 输入每个团队中所有队员的编号,要求支持如下3中指令: ENQUEUE x:编号为x的人进入长队 DEQUEUE:长队的队首出队 STOP:停止模拟 对于每个DEQUEUE指令,输出出队的人的编号。

题目描述

​PDF​

UVA540 Team Queue  队列入门经典_出队

输入输出格式

输入格式:

 

UVA540 Team Queue  队列入门经典_输入输出_02

 

输出格式:

 

UVA540 Team Queue  队列入门经典_出队_03

 

输入输出样例

输入样例#1: 复制


2 3 101 102 103 3 201 202 203 ENQUEUE 101 ENQUEUE 201 ENQUEUE 102 ENQUEUE 202 ENQUEUE 103 ENQUEUE 203 DEQUEUE DEQUEUE DEQUEUE DEQUEUE DEQUEUE DEQUEUE STOP 2 5 259001 259002 259003 259004 259005 6 260001 260002 260003 260004 260005 260006 ENQUEUE 259001 ENQUEUE 260001 ENQUEUE 259002 ENQUEUE 259003 ENQUEUE 259004 ENQUEUE 259005 DEQUEUE DEQUEUE ENQUEUE 260002 ENQUEUE 260003 DEQUEUE DEQUEUE DEQUEUE DEQUEUE STOP 0


队列入门经典

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define N 1100
typedef long long ll;
int main()
{
int T,caseP = 1;

while(scanf("%d",&T)==1&&T)
{
map<int,int>team; //team[x]=i表示x队员属于i
for(int i=0;i<T;i++)
{
int n;
scanf("%d",&n);
for(int j=1;j<=n;j++)
{
int x;
scanf("%d",&x);
team[x]=i;
}
}
printf("Scenario #%d\n",caseP++);
queue<int>q,q2[N];
//q表示团队队列,q2表示各队的队列
while(1)
{
string op;
cin>>op;
if(op[0]=='S')
break;
else if(op[0]=='D')
{
int t=q.front();
printf("%d\n",q2[t].front());
q2[t].pop();

if(q2[t].empty())
{
q.pop(); //及时删除
}
}
else if(op[0]=='E')
{
int x;
scanf("%d",&x);
int t=team[x];
if(q2[t].empty())
{
q.push(t);
}
q2[t].push(x);
}
}
cout<<endl;
}

return 0;
}

 

标签:q2,int,DEQUEUE,Queue,ENQUEUE,Team,UVA540,include,op
From: https://blog.51cto.com/u_14932227/6042476

相关文章