题解 | 字符串优先队列

字符串优先队列

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;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务