题解 | 【模板】堆

【模板】堆

https://www.nowcoder.com/practice/13f61c8c92404f5ea5d6fa4c692869fb

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int n;
priority_queue<int> q;

int main(){
    cin>>n;
    int top = 0;
    while(n--){
        string str;int x;
        cin>>str;
        if(str=="push") {
            cin>>x;
            q.push(x);
        }
        else if(str=="top"){
            if(q.empty()) puts("empty");
            else cout<<q.top()<<"\n";
        }
        else{
            if(q.empty()) puts("empty");
            else {
                cout<<q.top()<<"\n";
                q.pop();
            }
        }
    }


    return 0;
}

全部评论

相关推荐

zzzilik:没事的,才刚刚开始,后面会捞的,这个三天没人发起面试自动结束,但是面试官还是能看到简历,四月份主战场会慢慢捞
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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