안녕하십니까. Eun🦆입니다.
풀이법 입니다.
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> priorities, int location) {
int answer = 0;
int try_cnt = 0;
int pass_cnt = 0;
int size = priorities.size();
int cnt = 0;
vector<int> value;
for(int i=0;i<size;i++){
value.push_back(cnt);
cnt++;
}
//printf("value.size()=%d\n",value.size());
while(priorities.size()>0)
{
for(int i=0;i<priorities.size();i++)
{
int temp = 0;
int temp_check = 0;
if(priorities[0]<priorities[i])
{
temp = priorities[0];
priorities.erase(priorities.begin());
priorities.push_back(temp);
//for(int j=0;j<priorities.size();j++)
//printf("priorities[%d]=%d\n",j,priorities[j]);
//printf("changed!\n");
temp_check = value[0];
value.erase(value.begin());
value.push_back(temp_check);
//for(int j=0;j<value.size();j++)
//printf("value[%d]=%d\n",j,value[j]);
try_cnt++;
break;
}
else
{
if(i==priorities.size()-1)
{
pass_cnt++;
//printf("passed!\n");
//printf("priotities %d out!\n",priorities.front());
priorities.erase(priorities.begin());
//printf("value %d out!\n",value.front());
if(value.front()==location)
{
answer=pass_cnt;
//printf("answer=%d\n",answer);
}
value.erase(value.begin());
break;
}
}
}
}
return answer;
}
'개발 > Coding Test' 카테고리의 다른 글
[프로그래머스 C++ Lv2] 다리를 지나는 트럭 (0) | 2022.06.06 |
---|---|
[프로그래머스 C++ Lv2] 스킬트리 (0) | 2022.06.06 |
[프로그래머스 C++ Lv2] 주식가격 (0) | 2022.06.06 |
[프로그래머스 C++ Lv1] 예산 (0) | 2022.06.06 |
[프로그래머스 C++ Lv1] 직사각형 별찍기 (0) | 2022.06.06 |
댓글