HDU1509---Windows Message Queue

練手了,很久沒好好學了,寒假儘量充實一點。

題目的參數是沒用的數據- -、

#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> q;
    int i=1;
    char c[5];
    while(scanf("%s",c)!=EOF){
        if(c[0]=='G'){
            if(q.empty()) printf("EMPTY QUEUE!\n");
            else {
                node t=q.top();
                q.pop();
                cout<<t.name<<" "<<t.par<<endl;
            }
        }
        else {
            node t;
            cin>>t.name>>t.par>>t.pri;
            t.id=i++;
            q.push(t);
        }
    }
}


發佈了198 篇原創文章 · 獲贊 14 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章