1 #include<iostream>
2 #include<string>
3 #include<queue>
4 using namespace std;
5 int k;
6 struct sortt{
7 int pri;
8 int id;
9 friend bool operator<(sortt s1,sortt s2){
10 if(s1.pri==s2.pri) return s1.id>s2.id;
11 else
12 return s1.pri<s2.pri;
13 }
14 };
15 int main(){
16 int n;
17 int a,b;
18 sortt sor;
19 string str;
20 while(cin>>n){
21 priority_queue<sortt> q[4];
22 k=0;
23 while(n--){
24 cin>>str;
25 if(str=="OUT"){
26 cin>>a;
27 if(q[a].empty()==true)
28 cout<<"EMPTY"<<endl;
29 else{
30 sor=q[a].top();
31 q[a].pop();
32 cout<<sor.id<<endl;
33 }
34 }
35 else if(str=="IN"){
36 cin>>a>>b;
37 sor.id=++k;
38 sor.pri=b;
39 q[a].push(sor);
40 }
41 }
42 }
43 return 0;
44 }
原文:https://www.cnblogs.com/bxynlbyx/p/12815356.html