프린터

최성현·2021년 2월 1일
0
post-thumbnail

프로그래머스 프린터 문제

https://programmers.co.kr/learn/courses/30/lessons/42587![]

#include <string>
#include <vector>
#include <queue>
using namespace std;

int solution(vector<int> priorities, int location) {
    int answer = 0;
    priority_queue<int> q;
    queue<pair<int, int>> abc;

    for (int i = 0; i < priorities.size(); i++) {
        abc.push({ i,priorities[i] });
        q.push(priorities[i]);
    }

    while (!abc.empty()) {

        int a = abc.front().first; //가장앞에있는 문서 
        int b = abc.front().second; // 가장앞의 중요도 
        abc.pop();
        if (q.top() == b) { //가장 높은 중요도일때,
            q.pop();
            answer += 1; //1회증가 
            if (location == a) { //찾고자하는 순서
                break;
            }
        }
        else {
            
            
            abc.push({ a,b }); //뒤로 
        }



    }

    return answer;
}
int main() {
    vector<int> a = { 2,1,3,2 };

    solution(a, 2);

    return 0;
}
profile
후회없이

0개의 댓글