Gidhub BE Developer

BOJ - 최소 힙

2018-02-15
goodGid

Problem

Problem URL : 최소 힙

Screenshots of Problem Explain

Answer Code (1) [18. 02. 15]


#include<iostream>
#include<queue>
#include<functional>
using namespace std;

// Root is Min Value
priority_queue<int,vector<int>,greater<int> > pq;

int main(void) {
    int tc;
    cin >> tc;
    
    while (tc--) {
        int a;
        scanf("%d",&a);
        
        if( a==0 ){
            if( pq.empty() ){
                printf("0\n");
            }
            else{
                printf("%d\n",pq.top());
                pq.pop();
            }
        }
        else{
            pq.push(a);
        }
    }
    
    return 0;
}



Code Review

Answer Code (1) [18. 02. 15]

  • Code가 중요한게 아니다. Priority Queue 개념을 익히는게 중요하다.

Comments

Content