Algorithm/프로그래머스

[프로그래머스/C++] 기능개발

pinevienna 2021. 2. 17. 21:01

 

 

작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때

각 배포마다 몇 개의 기능이 배포되는지 반환하는 문제

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string>
#include <vector>
 
using namespace std;
 
vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    int temp, max_day = 0;
 
    for (int i = 0; i < progresses.size(); i++) {
        temp = (100 - progresses[i]) / speeds[i];
        if ((100 - progresses[i]) % speeds[i] != 0) temp++;
 
        if (answer.empty() || max_day < temp) {
            answer.push_back(1);
            max_day = temp;
        }
        else {
            answer.back()++;
        }
    }
 
    return answer;
}
cs

 

어렵진 않았으나 효율적으로 못짜서 다른 사람꺼 보고 수정함ㅎㅎ