<문제>
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다.
또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 기능보다 먼저 개발될 수 있고, 이때 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포됩니다.
먼저 배포되어야 하는 순서대로 작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때 각 배포마다 몇 개의 기능이 배포되는지를 return 하도록 solution 함수를 완성하세요.
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List answer = new List { };
int[] days = new int[progresses.Length];
int count = 0;
int max=0;
for(int i=0;i<progresses.Length;i++)
{
days[i] = (int)Math.Ceiling((double)(100 - progresses[i]) / speeds[i]);
}
for(int j=0;j<days.Length-1;j++)
{
if (count == 0)
count = 1;
if (days[j] >= days[j + 1] || max >= days[j+1])
{
count++;
if(max < days[j])
max = days[j];
}
else
{
answer.Add(count);
count = 0;
max=0;
}
}
if(count == 0)
answer.Add(1);
else
answer.Add(count);
return answer.ToArray();
}
}
'코딩연습 > 프로그래머스 코딩테스트' 카테고리의 다른 글
[프로그래머스] 완전탐색 - 직사각형 (0) | 2022.11.14 |
---|---|
Lv1. 과일장수 (0) | 2022.11.14 |
[프로그래머스] 핸드폰 번호 가리기 (0) | 2021.05.09 |
[오라클] 고양이와 개는 몇 마리 있을까? (0) | 2021.05.08 |
[프로그래머스]문자열 내림차순으로 배치하기 C# (0) | 2021.05.05 |