[Programmers] 프린터

프로그래머스 level2

Posted by kyoungIn on March 30, 2019

프린터

문제 링크 : (https://programmers.co.kr/learn/courses/30/lessons/42587)

풀이

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <string>
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
#define p pair<int,int>
int solution(vector<int> priorities, int location) {
    int answer = 0,len = priorities.size();
    vector<p> data(len);
    for(int i=0;i<len;i++)
        data[i]=p(priorities[i],i);
     sort(priorities.begin(),priorities.end(),greater<int>());
    int i=0;
   while(1){
        if(i==data.size())
            i=0;
        int val= data[i].first;
        int idx= data[i].second;
        if(val==priorities[0]){
           priorities.erase(priorities.begin());
           data.erase(data.begin()+i);
            cout <<data.size() <<endl;
            i--;
           ++answer;
           if(idx==location)
               break;
       }
        i++;
   }
    return answer;
}