정올문제풀이

4905 : STL - Priority Queue

파아란기쁨1 2022. 10. 20. 19:44
반응형
#include <bits/stdc++.h>

using namespace std;
/*
우선 순위 큐는 operator 에서 참인 조건이 가장 마지막에 나온다.
*/

struct data{
    string name;
    int age;
    double blood;
    bool operator < (const struct data &r)const{
        if(blood < r.blood) return true;
        else if(blood == r.blood) {
            return age < r.age;
        }
        return false;
    }
};

priority_queue <struct data> pq;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string cmd,name;
    int age;
    double blood;
    for(int i=0;i<n;i++){
        cin >> cmd;
        if(cmd == "push"){
            cin >> name >> age >> blood;
            pq.push({name,age,blood});
        }
        else if(cmd == "pop"){
            if(!pq.empty()){
                cout << pq.top().name <<"\n";
                pq.pop();
            }
        }
    }


    return 0;
}
반응형