Programmers Review

[Lv 2] 기능개발

hanseongbugi 2024. 6. 28. 16:59

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

큐를 사용해서 해결할 수 있다.

큐에 개발 기간을 저장한다.

큐에서 요소를 뽑고 뽑은 요소보다 작은 개발 기간이 존재하는 경우 함께 배포한다.

 

#include <string>
#include <vector>
#include <iostream>
#include <queue>
using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    
    queue<int> q;
    for(int i = 0;i<progresses.size();i++){
        int progress = progresses[i];
        int speed = speeds[i];
        
        int range = 100 - progress;
        int day = 0;
        while(range > 0){
            range -= speed;
            day++;
        }
        q.push(day);
    }
    while(!q.empty()){
        int now = q.front();
        q.pop();
        int process = 1;
        while(!q.empty()){
            int to = q.front();
            if(now >= to){
                process++;
                q.pop();
            }
            else
                break;
        }
        answer.push_back(process);
    }
    return answer;
}