프로그래머스 - 기능개발 - Level 2

Byungwoong An·2021년 7월 1일
0

문제

풀이전략

  1. 배포는 하루에 한번씩만 한다. 단 뒤에 있는 기능은 앞에 있는 기능이 다 배포가 되었을 경우 배포가 가능하다. 즉 앞에 일이 다 끝나야 뒤에 일을 해결할 수 있다.

코드

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    // 전체 시간으로 각 작업들의 속도와 비교할수 있다. 
    int time = 0;
    int res = 0;
    for(int i=0; i<progresses.size(); i++){
        // 작업이 100이 넘었는지 아닌지를 체크함
        // 만약 넘었을 경우 res를 증가시킴
        if(progresses[i]+time*speeds[i] >= 100){
            
            res++;
        }
        else{
            if(i != 0){
                printf("%d %d %d\n",time,res, i);
                // 이후 res값을 answer에 넣음. 즉 작업 완료된 개수를 넣기
                answer.push_back(res);
                res = 0;
            } 
            // 다음 작업이 완료될때까지 시간을 늘림
            while(progresses[i]+time*speeds[i] < 100){
                time++;
            }    
            // 작업 하나가 완료되었으므로 res++을 해줌. 
            res++;
        }
    }
    if(res != 0) answer.push_back(res);
    return answer;
}

소감

큐를 사용하지 않고, 문제를 해결한 것. 사실 단순한 문제였으므로 그냥 한번 쭉 읽어만 보자.

profile
No Pain No Gain

0개의 댓글