前言
- 优先队列的应用
- 注意结构体重写运算符的写法
#include <iostream>
#include <queue>
#include <string>
using namespace std;
struct patient {
int priority, ID;
friend bool operator < (const patient x, const patient y) {
if (x.priority == y.priority)
return x.ID > y.ID;
return x.priority < y.priority;
}
};
int main() {
int N, A, B;
string opt;
while (cin >> N) {
priority_queue<patient> que[4];
int i = 0;
while (N--) {
cin >> opt;
if (opt == "IN") {
cin >> A >> B;
i++;
que[A].push({B, i});
}
else {
cin >> A;
if (que[A].empty())
cout << "EMPTY" << endl;
else {
cout << que[A].top().ID << endl;
que[A].pop();
}
}
}
}
}