现在的位置: 首页 > 综合 > 正文

hdu1509 Windows Message Queue

2018年04月23日 ⁄ 综合 ⁄ 共 504字 ⁄ 字号 评论关闭

优先队列水题,真心不懂那个<号到底要怎么重载

code:

#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

struct Win
{
    char name[50];
    int id,val,parameter;
    friend bool operator < (Win a,Win b)
    {
        if(a.val==b.val)
        {
            return b.id<a.id;
        }
        return b.val<a.val;
    }
}tmp;
priority_queue<Win> q;
int main()
{
    char str[5];
    int k=0;
    while(~scanf("%s",str))
    {
        if(str[0]=='G')
        {
            if(q.empty())
            {
                puts("EMPTY QUEUE!");
            }else{
                tmp=q.top();
                q.pop();

                printf("%s %d\n",tmp.name,tmp.parameter);
            }
        }else{
            scanf("%s%d%d",tmp.name,&tmp.parameter,&tmp.val);
            tmp.id=++k;
            q.push(tmp);
        }
    }
    return 0;
}

抱歉!评论已关闭.