2025년, 코딩은 선택이 아닌 필수!

2025년 모든 학교에서 코딩이 시작 됩니다. 먼저 준비하는 사람만이 기술을 선도해 갑니다~

정올문제풀이

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;
}
반응형

'정올문제풀이' 카테고리의 다른 글

4639 : Tutorial: STL Set 3  (0) 2022.10.23
4637 : Tutorial: STL Set 1  (0) 2022.10.22
5203 : 식사 계획 세우기  (0) 2022.10.18
5202 : 레벨 업  (0) 2022.09.19
5227 : LR 수집기 2  (0) 2022.09.19