-
[programmers] 프린터 / C++공부/PS (programmers) 2022. 5. 18. 00:35
https://programmers.co.kr/learn/courses/30/lessons/42587
#include <string> #include <vector> #include <queue> #include <iostream> using namespace std; int solution(vector<int> priorities, int location) { int answer = 0, cnt = 1; int sequence[110] = {0, }; // 각 문서가 프린트된 순서를 저장 queue <pair<int, int>> q; priority_queue <int> pq; for(int i=0; i<priorities.size(); i++) { q.push({i,priorities[i]}); // index, priority pq.push(priorities[i]); // 중요도의 내림차순 정렬 } while(!q.empty()) { int cur_idx = q.front().first; int cur_priority = q.front().second; int top_priority = pq.top(); q.pop(); if(cur_priority >= top_priority) { pq.pop(); sequence[cur_idx] = cnt++; //cout << "sequence[" << cur_idx << "] = (cnt) " << cnt << "\n"; } else { q.push({cur_idx, cur_priority}); //cout << "q.push(" << cur_idx << ", " << cur_priority << ")\n"; //cout << "cnt = " << cnt << "\n"; } } answer = sequence[location]; return answer; }
'공부 > PS (programmers)' 카테고리의 다른 글
[programmers] 폰켓몬 / C++ (0) 2022.07.27 [programmers] 이상한 문자 만들기 / C++ (0) 2022.07.20 [programmers] 제일 작은 수 제거하기 / C++ (0) 2022.07.19 [programmers] 소수 만들기 / C++ (0) 2022.07.19 [programmers] 두 개 뽑아서 더하기 / C++ (0) 2022.07.19