且未

博客园 首页 新随笔 联系 订阅 管理

运算符重载

题目

#include<stdio.h>
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;


struct node{
    string name;
    int par,pri,id;
    friend bool operator< (node a,node b){
        if(a.pri==b.pri)
            return a.id >b.id;
            else return a.pri >b.pri;
    }
};


int main()
{
    priority_queue <node> que;
    char a[5];
    int i=0;
    while(~scanf("%s",a))
    {
        if(a[0]=='G')
        {
            if(que.empty())
                printf("EMPTY QUEUE!\n");
            else
            {
                node m = que.top();
                //printf("%s %d\n",m.name,m.par);
                cout<<m.name<<" "<<m.par<<endl;
                que.pop();
            }
        }
        if(a[0]=='P')
        {
            node t;
           // scanf("%s%d%d",t.name,&t.par,&t.pri);
           cin>>t.name>>t.par>>t.pri;
            t.id=i++;
            que.push(t);
        }
    }


    return 0;
}


posted on 2017-07-10 20:09  阿聊  阅读(76)  评论(0编辑  收藏  举报