GitHubSeob
C++ / 프로그래머스 / 기능개발 본문
문제 |
https://programmers.co.kr/learn/courses/30/lessons/42586
코딩테스트 연습 - 기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는
programmers.co.kr
문제풀이 |
반복문을 통해 progresses와 speeds를 탐색한다.
변수day를 선언하여 해당 작업이 걸리는 일수를 저장한다.
해당 일에 작업을 할 수 있으면 큐에 저장한다.
해당 일에 작업을 할 수 없으면 큐에 있는 작업의 개수를 answer에 push_back한다.
그 다음 해당 일에 작업하지 못한 작업은 얼마나 걸리는지 계산을 하여 day의 값을 바꾼다.
day를 계산 할때는 올림을 하기 위해 분자에는 speeds[idx] - 1 값을, 분모에는 speeds[idx] 값을 더해준다.
코드 |
#include <string>
#include <vector>
#include <queue>
using namespace std;
vector<int> solution(vector<int> progresses, vector<int> speeds) {
int day(0);
vector<int> answer;
queue<int> list;
for (int idx = 0; idx < speeds.size(); ++idx) {
if (progresses[idx] + speeds[idx] * day < 100) {
if (!list.empty()) {
answer.push_back(list.size());
while (!list.empty()) {
list.pop();
}
}
day = (100 - progresses[idx] + speeds[idx] - 1) / speeds[idx];
}
list.push(idx);
}
if (!list.empty()) {
answer.push_back(list.size());
}
return answer;
}
'Programmers > Level 2' 카테고리의 다른 글
C++ / 프로그래머스 / 짝지어 제거하기 (0) | 2022.04.14 |
---|---|
C++ / 프로그래머스 / 더 맵게 (0) | 2022.04.14 |
C++ / 프로그래머스 / 124 나라의 숫자 (0) | 2022.04.14 |
C++ / 프로그래머스 / 멀쩡한 사각형 (0) | 2022.04.14 |
C++ / 프로그래머스 / 오픈채팅방 (0) | 2022.04.13 |