[프로그래머스 문제풀이] 7. 기능개발

WIGWAG·2023년 1월 1일
0

프로그래머스

목록 보기
7/32

올림((100 - 개발진행률) / 작업속도) = 남은 작업기간
여기서 올림 함수인 ceil을 생각했지만 다른 사람의 코드를 참고해서 이렇게 바꿨다.

((99-개발진행률)/ 작업속도) + 1 = 남은 작업기간

이걸로 쓸데없이 함수를 호출하는 일을 막았다.

#include <string>
#include <vector>
#include <iostream>

using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    int number = 0;
    vector<int> answer;
    for (int index = 0, diff = 0; index < progresses.size(); )
    {
        if (progresses[index] + speeds[index] * diff >= 100)
        {
            ++index;
            ++number;
        }
        else
        {
            diff = (99 - progresses[index]) / speeds[index] + 1;
            if (index == 0) continue;
            answer.push_back(number);
            number = 0;
        }
    }

    answer.push_back(number);
    return answer;
}

int main()
{
	for (auto d : solution({ 93, 30, 55 }, { 1,30,5 }))
	{
		cout << d << ' ';
	}
}

실행결과

2 1


기능개발 문제 링크

profile
윅왁의 프로그래밍 개발노트

0개의 댓글