题解 | 字符串优先队列
字符串优先队列
https://www.nowcoder.com/practice/7f3c2ebfc3be442897393f7da5d021c8
#include<bits/stdc++.h>
using namespace std;
priority_queue<string, vector<string>, greater<string>> s;
void insertValue(string x){
// TODO: 实现插入操作
s.push(x);
return;
}
void deleteValue(){
// TODO: 实现删除操作
s.pop();
return;
}
string getTop(){
// TODO: 返回字典序最小的字符串
return s.top();
}
int main(){
int q,op;
string x;
cin>>q;
while(q--){
cin>>op;
if(op==1){
cin>>x;
insertValue(x);
}
if(op==2){
cout<<getTop()<<endl;
}
if(op==3){
deleteValue();
}
}
return 0;
}
