---
layout: post
title:  " [Programmers] 42587. 프린터 "
categories: Algorithm
tags: Programmers reSolve
author: goodGid
---
* content
{:toc}

## Problem 
Problem URL : **[프린터](https://programmers.co.kr/learn/courses/30/lessons/42587)**








---

## [1] Answer Code (18. 09. 27)

``` cpp
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#define p pair<int,int>
using namespace std;

int solution(vector<int> priorities, int location) {
    int answer = 0;
    queue<p> q;
    priority_queue<int> pq;
    int size = (int) priorities.size();
    for(int i=0; i<size; i++){
        q.push( {priorities[i],i} );
        pq.push(priorities[i]);
    }

    while(! q.empty()){
        int value = q.front().first;
        int idx = q.front().second;
        q.pop();
        if( pq.top() == value){
            pq.pop();
            answer++;
            if(idx == location)
                break;
        }
        else{
            q.push( {value,idx} );
        }
    }
    return answer;
}
```

### Review

* priority_queue에 top과 queue에 front가 같다 && 그 index도 같다면 답을 출력시켜주면 된다. 

* BOJ에는 [1966. 프린터 큐]({{site.url}}/BOJ-1966/)라는 이름으로 있다.

* 출처는 [The 2006 ACM Northwestern European Programming Contest](http://www.csc.kth.se/contest/nwerc/2006/problems/nwerc06.pdf)이다.

Write PGM Post " 42587. 프린터 "
Write PGM Post " 42587. 프린터 "
