프로그래머스(C++) - 프로세스

2025. 10. 8. 13:29·C++ 프로그래머스 다이어리/Stack,Queue

●문제

 

●입출력

 

문제해석

priorities 우선도 수치가 높으면 priorities의 n번째와 n +1 숫자의 순위가 변경

숫자가 우선도 수치대로 정돈된뒤 location의 위치를 return

 

푼방법

프린터 큐 방식대로 큐에 priorities.size()만큼 프로세스를 담고

max수치면 출력 아니면 큐에 담기

#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>

using namespace std;

int solution(vector<int> priorities, int location) 
{
    //index, priorities
    queue<pair<int, int>>q;
    for (int i = 0; i < priorities.size(); i++)
        q.push({ i, priorities[i] });
    int process_Count = 0;
    while (!q.empty())
    {
        int max_Process = *max_element(priorities.begin(), priorities.end());
        //index, priorities
        pair<int, int> current = q.front();
        q.pop();

        if (current.second == max_Process)
        {
            process_Count++;

            priorities[current.first] = -1;
            if (current.first == location)
                return process_Count;
        }
        else
        {
            q.push(current);
        }
    }
    return -1;
}

 

레벨 : 2

점수 : 2

'C++ 프로그래머스 다이어리 > Stack,Queue' 카테고리의 다른 글

프로그래머스(C++) - 괄호 회전하기  (0) 2025.10.14
프로그래머스(C++) - 주식가격  (0) 2025.10.08
프로그래머스(C++) - 기능개발  (0) 2025.08.07
Algorithm - Stack, Queue  (0) 2025.08.07
프로그래머스(C++) - 짝지어 제거하기  (0) 2025.08.02
'C++ 프로그래머스 다이어리/Stack,Queue' 카테고리의 다른 글
  • 프로그래머스(C++) - 괄호 회전하기
  • 프로그래머스(C++) - 주식가격
  • 프로그래머스(C++) - 기능개발
  • Algorithm - Stack, Queue
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (173) N
      • Unreal5 프로젝트 다이어리 (73)
      • Unreal5 프로젝트 다이어리2 (11)
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • 코드 개인보관함 (8)
      • C++ 프로그래머스 다이어리 (50) N
        • Stack,Queue (6)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (6)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (14) N
      • 코딩테스트+@ (11) N
      • 알고리즘 스타디 (1)
      • 알고리즘 스타디 과제 (3)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    unreal 컷씬
    unreal look at
    언리얼 foot step
    언리얼 페이드 아웃
    unreal 모션매칭
    unreal sequence
    unreal 로딩
    언리얼 컷씬
    언리얼 look at
    언리얼 로딩
    언리얼 behavior tree
    언리얼 motionmatching
    unreal loading
    언리얼 behaviortree
    언리얼 로딩창
    언리얼 시퀀스
    언리얼 모션매칭
    unreal 시퀀스
    언리얼
    언리얼 비헤이비어트리
  • hELLO· Designed By정상우.v4.10.3
lucodev
프로그래머스(C++) - 프로세스
상단으로

티스토리툴바