hdu1509 Windows Message Queue

優先隊列水題,真心不懂那個<號到底要怎麼重載

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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章