
앞쪽에 있는 기능이 전부 개발되었다면 앞에서부터 기능이 개발되지 않은 것이 나올 때까지 pop 해주고
그 cnt를 answer에 저장해주면 된다.
우선 progresses와 speeds를 전부 큐에 넣어주고 반복문을 통해 0번 위치의 기능을 수행하는 데에
얼마나 걸리는지 세준다. 이후 현재 날 * speed의 front + q의 front가 100보다 크다면 그 기능도
이미 완료되었기 때문에 pop 해주면 된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <string>
#include <vector>
#include <queue>
using namespace std;
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
queue<int> q, sp;
for (int i : progresses) q.push(i);
for (int i : speeds) sp.push(i);
while (!q.empty()) {
int cnt = 1;
int day = 0;
int cur = q.front(); q.pop();
int spd = sp.front(); sp.pop();
while(cur < 100) cur += spd, ++day;
while(!q.empty() && sp.front() * day + q.front() >= 100) {
sp.pop(), q.pop(), ++cnt;
}
answer.push_back(cnt);
}
return answer;
}
|
cs |
'Programmers' 카테고리의 다른 글
프로그래머스 실패율 (0) | 2020.12.26 |
---|---|
C++ 단어 변환 (0) | 2020.11.28 |
[프로그래머스 C++] 카카오프렌즈 컬러링북 (0) | 2020.09.28 |
[프로그래머스 C++] 소수 찾기 (0) | 2020.09.27 |
[프로그래머스 C++] 완주하지 못한 선수 (0) | 2020.09.26 |