728x90
반응형
using System.Collections.Generic;
public class Solution
{
public int solution(int[] priorities, int location)
{
Queue<KeyValuePair<int, int>> printer = new Queue<KeyValuePair<int, int>>();
Queue<KeyValuePair<int, int>> priorityPrinter = new Queue<KeyValuePair<int, int>>();
for (int i = 0; i < priorities.Length; ++i)
printer.Enqueue(new KeyValuePair<int, int>(i, priorities[i]));
int answer = 0;
while (printer.Count > 0)
{
var dequeue = printer.Dequeue();
bool max = true;
foreach (var peek in printer)
{
if (peek.Value > dequeue.Value)
{
max = false;
break;
}
}
if (max)
{
priorityPrinter.Enqueue(dequeue);
answer++;
if (dequeue.Key == location)
return answer;
}
else
{
printer.Enqueue(dequeue);
}
}
return 0;
}
}
반응형
'프로그래밍 > 기타' 카테고리의 다른 글
구글 스토어 앱 등록 (10) | 2020.10.03 |
---|---|
프로그래머스 - 다리를 지나는 트럭 (C#) (0) | 2020.09.20 |
Tearing (티어링) (2) | 2020.05.02 |
IO 게임 (0) | 2020.04.14 |
Sourcetree (소스트리) 사용법 (3) | 2020.04.11 |