使用map,并将优先级值放在first以自动排序,如果输入的代码为2,就输出最后一组元素的second并删去,输入代码为3时同理。
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(void){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
map <int,int> arr;
int code,number,priority;
while(cin>>code){
if (code==0){
break;
}
else if(code==1){
cin>>number>>priority;
arr.insert(make_pair(priority, number));
}
else if(code==2){
if (arr.empty()){
cout<<"0"<<"\n";
}
else{
map<int,int>::iterator last=--arr.end();
cout<<last->second<<"\n";
arr.erase(last);
}
}
else if(code==3){
if (arr.empty()){
cout<<"0"<<"\n";
}
else {
cout<<arr.begin()->second<<"\n";
arr.erase(arr.begin());
}
}
}
}
标签:priority,arr,code,map,Double,number,Queue,POJ3481,include
From: https://blog.csdn.net/2403_87149971/article/details/143582538