[프로그래머스 C++] 프로세스

 

https://school.programmers.co.kr/learn/courses/30/lessons/42587

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


 

 

해결전략

 

Queue 큐, Priority_Queue 우선순위 큐 

 


 

코드

 

#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(vector<int> priorities, int location) {
queue<pair<int,int>> Q;
priority_queue<int> pQ;
for (int i = 0; i < priorities.size(); i++) {
Q.push({priorities[i], i});
pQ.push(priorities[i]);
}
int answer = 1;
while(!Q.empty())
{
if(Q.front().first == pQ.top())
{
if (Q.front().second == location) {
return answer;
}
Q.pop();
pQ.pop();
answer++;
}
else
{
pair<int,int> tmp = Q.front();
Q.pop();
Q.push(tmp);
}
}
return answer;
}