Skip to content

Commit ee2bd58

Browse files
jjuchanYoepee
andauthored
feat: 프로그래머스 42586 기능개발 문제 풀이 추가 (#7)
Co-authored-by: Dongyeop <[email protected]>
1 parent 12b3922 commit ee2bd58

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

.idea/.name

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/week02/Juchan/PG_42586.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package week02.Juchan;
2+
3+
import java.util.ArrayList;
4+
import java.util.LinkedList;
5+
import java.util.List;
6+
import java.util.Queue;
7+
8+
public class PG_42586 {
9+
static class Solution {
10+
public int[] solution(int[] progresses, int[] speeds) {
11+
// 각 작업이 완료되기까지 남은 '일 수'를 저장할 큐
12+
Queue<Integer> queue = new LinkedList<>();
13+
14+
//(100-진도율)/개발 속도를 통해 남은 일 수 계산
15+
for (int i = 0; i < progresses.length; i++) {
16+
int day = (int) Math.ceil((100.0 - progresses[i]) / speeds[i]); //ex 3.8888 일이면 4일 필요하기에 ceil 함수를 사용해서 올림 처리 후 형 변환
17+
queue.offer(day);
18+
}
19+
List<Integer> result = new ArrayList<>();
20+
21+
// 첫번 째 배포 일 수를 뽑아냅니다.
22+
while (!queue.isEmpty()) {
23+
int current = queue.poll();
24+
int count = 1;
25+
26+
// 배포일과 비교하여 큐의 첫 번째 일 수가 작거나 같으면 같이 묶어서 리스트에 저장합니다.
27+
while (!queue.isEmpty() && queue.peek() <= current) {
28+
queue.poll();
29+
count++;
30+
}
31+
result.add(count);
32+
}
33+
int[] answer = new int[result.size()];
34+
for (int i = 0; i < result.size(); i++) {
35+
answer[i] = result.get(i);
36+
}
37+
return answer;
38+
}
39+
}
40+
41+
public static void main(String[] args) { //테스트
42+
Solution solution = new Solution();
43+
44+
45+
int[] progresses = {93, 30, 55};
46+
int[] speeds = {1, 30, 5};
47+
48+
int[] result = solution.solution(progresses, speeds);
49+
50+
51+
System.out.print("[");
52+
for (int i = 0; i < result.length; i++) {
53+
System.out.print(result[i]);
54+
if (i != result.length - 1) { //마지막 요소는 , 를 빼줍니다.
55+
System.out.print(", ");
56+
}
57+
}
58+
System.out.println("]");
59+
// 예상 출력: [2, 1]
60+
}
61+
}
62+
63+
64+
/**
65+
* 문제
66+
* 각각 기능은 진도(progress) 가 있고, 매일 각 기능마다 개발 속도(speed) 만큼 진도가 올라간다.
67+
* 기능은 진도가 100% 이상이 되어야 배포 할 수 있다.
68+
* 배포는 하루에 한 번, 하루가 끝난 후 진행한다.
69+
* 진도가 뒤에 있는 기능이 앞 기능보다 빨리 끝날 수 있는데 뒤에 있는 기능은 앞 기능이 배포되는 시점에 같이 배포된다.
70+
* <p>
71+
* 풀이 방법
72+
* 1. 각 기능마다 100%가 될 때까지 걸리는 날을 계산한다.(100-진도율)/개발 속도
73+
* 2. 큐에서 가장 앞에 있는 기능을 꺼내 배포일을 지정한다.
74+
* 3. 배포일보다 작업이 먼저 끝난 뒤에 있는 기능도 같이 묶어준다.
75+
* 4. 묶인 기능의 수를 리스트에 넣어준다.
76+
* 5. 리스트를 출력한다.
77+
*/

0 commit comments

Comments
 (0)