●문제

●입출력

문제해석
priorities 우선도 수치가 높으면 priorities의 n번째와 n +1 숫자의 순위가 변경
숫자가 우선도 수치대로 정돈된뒤 location의 위치를 return
푼방법
프린터 큐 방식대로 큐에 priorities.size()만큼 프로세스를 담고
max수치면 출력 아니면 큐에 담기
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;
int solution(vector<int> priorities, int location)
{
//index, priorities
queue<pair<int, int>>q;
for (int i = 0; i < priorities.size(); i++)
q.push({ i, priorities[i] });
int process_Count = 0;
while (!q.empty())
{
int max_Process = *max_element(priorities.begin(), priorities.end());
//index, priorities
pair<int, int> current = q.front();
q.pop();
if (current.second == max_Process)
{
process_Count++;
priorities[current.first] = -1;
if (current.first == location)
return process_Count;
}
else
{
q.push(current);
}
}
return -1;
}
레벨 : 2
점수 : 2
'C++ 프로그래머스 다이어리 > Stack,Queue' 카테고리의 다른 글
| 프로그래머스(C++) - 괄호 회전하기 (0) | 2025.10.14 |
|---|---|
| 프로그래머스(C++) - 주식가격 (0) | 2025.10.08 |
| 프로그래머스(C++) - 기능개발 (0) | 2025.08.07 |
| Algorithm - Stack, Queue (0) | 2025.08.07 |
| 프로그래머스(C++) - 짝지어 제거하기 (0) | 2025.08.02 |
