공부/C#

[C#] 프로그래머스 스택/큐 - 프로세스

굴러다니다니 2025. 3. 9. 18:18
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/42587

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

using System;
using System.Collections.Generic;

public class Solution {
    public int solution(int[] priorities, int location) {
        int answer = 0;
        Queue<(int, int)> queue = new Queue<(int, int)>(); //index, priority
        for (int i = 0; i < priorities.Length; i++){
            queue.Enqueue((i, priorities[i])); //(0,2) (1,1) (2,3) (3,2)
        }
        Array.Sort(priorities);
        Array.Reverse(priorities);
        while(true){
            var (a, b) = queue.Dequeue();
            if (b == priorities[answer]){
                answer++;
                if (a == location) return answer;
            }
            else{
                queue.Enqueue((a, b));
            }
        }
        
    }
}
728x90