HDOJ1509数据结构

此题要注意以下一句话:

Note that one message can appear twice or more and if two messages have the same priority, the one comes first will be processed first.(i.e., FIFO for the same priority.) Process to the end-of-file.
 
然后用一个优先队列就可以了。
# include <iostream>
# include <stdio.h>
# include <queue>
# include <string.h>
using namespace std;
struct node{
    char Name[100];
    int Date;
    int Priority;
    int num;
     bool operator < (const node &a)const
    {
         if(a.Priority!=Priority)
             return a.Priority<Priority;
         else
             return a.num<num;
    }
};

int main()
{
    priority_queue<node> v;
    char x[100];
    node y;
    int q=1;
    while(scanf("%s",x)!=EOF)
    {
        if(x[0]=='G')
        {
            if(!v.empty())
            {
                printf("%s %d\n",v.top().Name,v.top().Date);
                v.pop();
            }
            else
                printf("EMPTY QUEUE!\n");
        }
        else
        {
            scanf("%s%d%d",y.Name,&y.Date,&y.Priority);
            y.num=q;
            q++;
            v.push(y);
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值