【杭电】[1873]看病要排队

这里写图片描述
这里写图片描述

优先队列的简单运用
priority_queueq[4];
也就是通过建立一个node包含有逻辑判断的结构体类型的优先队列,在模拟看病排队的过程

#include<stdio.h>
#include<queue>
using namespace std;
struct node {
    int num,lv;
    bool friend operator<(node a,node b) {
        if (a.lv==b.lv)
            return a.num>b.num;
        else
            return a.lv<b.lv;
    }
} a;
int main() {
    int n;
    while(scanf("%d",&n)!=EOF) {
        priority_queue<node>q[4];
        char s[5];
        int t,cnt=0;
        while(n--) {
            scanf("%s",s);
            if(s[0]=='I') {
                scanf("%d %d",&t,&a.lv);
                a.num=++cnt;
                q[t].push(a);
            } else {
                scanf("%d",&t);
                if(q[t].empty())
                    printf("EMPTY
");
                else {
                    a=q[t].top();
                    printf("%d
",a.num);
                    q[t].pop();
                }
            }
        }
    }
    return 0;
}

题目地址:【杭电】[1873]看病要排队

原文地址:https://www.cnblogs.com/BoilTask/p/12569718.html