문제
https://school.programmers.co.kr/learn/courses/30/lessons/42586
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <string>
#include <vector>
#include <iostream>
using namespace std;
/*
- progresses 작업 진도
- speed 작업 속도
만약 앞의 순서 작업이 안 끝났다면, 뒷 순서 progress도 배포 X
한 번에 배포되는 기능의 수.
5 1 1 6 1 7 8
*/
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer; // 날짜
vector<int> finishDays;
int sizeNum = progresses.size();
int finish = 100;
for(int i =0; i<sizeNum; i++)
{
int day = 0;
int tmp = progresses[i];
while (tmp < finish)
{
tmp += speeds[i];
++day;
}
finishDays.push_back(day);
}
/*
for(int &day : finishDays)
{
cout << day << " ";
}
*/
int x1 = 0;
int x2 = 1;
int func = 1;
while (x2 < sizeNum) {
// 뒤에 있는 기능이 기준 기능보다 "늦게" 끝난다 → 이제까지 모은 걸 한 번에 배포
if (finishDays[x2] > finishDays[x1]) {
// 지금까지 모은 개수 넣기
answer.push_back(func);
// 새 묶음 시작
x1 = x2; // 이제 x2가 새 기준
x2 = x1 + 1;
func = 1; // 새 묶음이니까 다시 1
}
else {
// 뒤에 있는 기능이 기준일보다 "빨리 끝나거나 같은 날 끝남" → 같이 배포
func++;
x2++; // 다음 기능 보러 감
}
}
// 마지막 묶음 넣기 (while 빠져나오면 아직 안 넣은 거 하나 남아 있음)
answer.push_back(func);
return answer;
}
'코딩 테스트 > C++' 카테고리의 다른 글
| 프로그래머스, C++) Lv 2. 연속 부분 수열 합의 개수 (0) | 2025.11.08 |
|---|---|
| 프로그래머스, C++) Lv 2. 예상 대진표 (0) | 2025.11.08 |
| 프로그래머스, C++) Lv 2. 프로세스 (0) | 2025.11.04 |
| 프로그래머스, C++) Lv 2. 피로도 (0) | 2025.11.04 |
| 프로그래머스, C++) Lv 2. 의상 (0) | 2025.10.24 |