둥지/알고리즘
[프로그래머스] 프로세스
까닭
2023. 5. 4. 13:10
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> priorities, int location)
{
int answer = 0;
//max_element() 늘 기억하자
int max = *max_element(priorities.begin(), priorities.end());
while (true)
{
for (int i = 0; i < priorities.size(); ++i)
{
if (priorities[i] == max)
{
++answer;
if (i == location)
{
return answer;
}
priorities[i] = 0;
max = *max_element(priorities.begin(), priorities.end());
}
}
}
}