好吧我承认重载运算符时还看了一下题解。
不过这题真的没问题了。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
const int N = 5000;
const int INF = 1000000;
struct node
{
int w, par, ord;
char name[100];
friend bool operator < (const node &a, const node &b)
{
if(a.w != b.w) return a.w > b.w;
else return a.ord > b.ord;
}
};
int main()
{
// freopen("in.txt", "r", stdin);
char a[5];
int n, k, num = 0;
priority_queue <node> q;
while(~scanf("%s", a))
{
if(!strcmp("PUT", a))
{
node tmp;
cin >> tmp.name;
scanf("%d%d", &tmp.par, &tmp.w);
num ++;
tmp.ord = num;
q.push(tmp);
}
else if(!strcmp("GET", a))
{
if(q.empty()) printf("EMPTY QUEUE!\n");
else
{
node tmp1 = q.top();
q.pop();
printf("%s %d\n", tmp1.name, tmp1.par);
}
}
}
return 0;
}