hdu 1873 看病要排队

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873

题目大意:根据所给的病人的编号ID和医生的编号,以及病人要求的哪位医生进行诊治,优先级的高的先进行诊治。这里注意输出的顺序,是从一开始进来的病人顺序进行编号。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <queue>
 5 using namespace std;
 6 
 7 queue<int>q[4][11];
 8 int find(int n)
 9 {
10     for (int i=10; i>0; i--)
11     {
12         if (!q[n][i].empty())
13         {
14             int g=q[n][i].front();
15             q[n][i].pop();
16             return g;
17         }
18     }
19     return -1;
20 }
21 int main ()
22 {
23     int t,n;
24     char ch[11];
25     while (cin>>t)
26     {
27         n=1;
28         for (int i=1; i<4; i++)
29             for (int j=1; j<11; j++)
30             {
31                 while (!q[i][j].empty())
32                     q[i][j].pop();
33             }
34         while (t--)
35         {
36             scanf("%s",&ch);
37             if (strcmp(ch,"IN")==0)
38             {
39                 int a,b;
40                 cin>>a>>b;
41                 q[a][b].push(n);
42                 n++;
43             }
44             else if (strcmp(ch,"OUT")==0)
45             {
46                 int d;
47                 cin>>d;
48                 int s=find(d);
49                 if (s==-1)
50                     printf ("EMPTY\n");
51                 else
52                     printf ("%d\n",s);
53             }
54         }
55 
56     }
57     return 0;
58 }

 

转载于:https://www.cnblogs.com/qq-star/p/3877941.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值