https://school.programmers.co.kr/learn/courses/30/lessons/42587
구현 아이디어 2분 구현 11분
#include <string>
#include <vector>
#include <queue>
using namespace std;
// 큐, 우선순위 큐 2개를 가지고 실행 순서 판별.
// 큐에는 A, B, C, D 순서, 우선순위 큐는 우선순위 순서.
struct Data
{
char name;
int priority;
Data(char name, int priority)
{
this->name = name;
this->priority = priority;
}
};
int solution(vector<int> priorities, int location) {
int answer = 0;
char check_data;
queue<Data> Q;
priority_queue<int> pQ;
for(int i = 0; i < priorities.size(); ++i)
{
Q.push(Data(i + 'A', priorities[i]));
pQ.push(priorities[i]);
if(i == location) check_data = i + 'A';
}
int cnt = 0;
while(!Q.empty())
{
Data cur_data = Q.front();
Q.pop();
if(cur_data.priority == pQ.top())
{
pQ.pop();
++cnt;
if(check_data == cur_data.name)
{
answer = cnt;
break;
}
}
else Q.push(cur_data);
}
return answer;
}