Notice
Recent Posts
Recent Comments
-
[프로그래머스] 레벨 2 - 기능개발 본문
https://programmers.co.kr/learn/courses/30/lessons/42586?language=cpp
루프를 한 번만 돌면서 풀 수 있는 문제는 가급적 여러번 for문 쓰지 말고 바로 풀자.
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
30
31
32
33
|
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
vector<int> remain;
for(int i=0; i<progresses.size(); i++){
if(((100 - progresses[i]) % speeds[i]) == 0){
remain.push_back((100 - progresses[i]) / speeds[i]);
}
else{
remain.push_back((100 - progresses[i]) / speeds[i] + 1);
}
}
// 7, 3, 9
int cur = remain[0];
int cnt = 1;
for(int i=1; i<remain.size(); i++){
if(cur < remain[i]){
answer.push_back(cnt);
cnt = 1;
cur = remain[i];
}
else{
cnt++;
}
if(i==remain.size()-1)
answer.push_back(cnt);
}
return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'1-4. 프로그래머스' 카테고리의 다른 글
[프로그래머스] 레벨 2 - 주식가격 (0) | 2020.02.04 |
---|---|
[프로그래머스] 레벨 2 - 다리를 지나는 트럭 (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 프린터 (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 탑 (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 카카오프렌즈 컬러링북 (2017 카카오코드 예선) (0) | 2020.02.03 |
Comments