기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다.
또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 기능보다 먼저 개발될 수 있고, 이때 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포됩니다.
먼저 배포되어야 하는 순서대로 작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때 각 배포마다 몇 개의 기능이 배포되는지를 return 하도록 solution 함수를 완성하세요.
progresses | speeds | return |
---|---|---|
[93, 30, 55] | [1,30,5] | [2,1] |
[95, 90, 99, 99, 80, 99] | [1,1,1,1,1] | [1,3,2] |
테스트 케이스 중 절반만 맞아서 포기를 하였다
반례가 너무 많아
def solution(progresses, speeds):
answer = []
pair = []
deployment = []
total = 0
for i in zip(progresses, speeds):
pair.append(list(i))
print(pair)
for p in pair:
date = 1
rate = p[0] + p[1] * date
if rate >= 100:
date = 1
#deployment.append(date)
while rate < 100:
date += 1
rate = p[0] + p[1] * date
print(p[0], p[1], rate)
print("작업완료날짜 : ", date)
deployment.append(date)
print(deployment)
for i in range(len(deployment) -1 ):
print(deployment[i], deployment[i+1])
if deployment[i] >= deployment[i+1]:
total += 1
else:
answer.append(total + 1)
total = 0
answer.append(total + 1)
print(answer)
return answer
배열에서 진도율 100 이상이 되면 배열에서 제거하고 다음 값에 time을 곱해줄 때도 100이 넘으면 count 를 더해줌
def solution(progresses, speeds):
answer = []
time = 0
count = 0
while len(progresses)> 0:
if (progresses[0] + time*speeds[0]) >= 100:
progresses.pop(0)
speeds.pop(0)
count += 1
print(progresses, speeds, count)
else: # 100 미만이고 if 조건 충족 안되면 time +1
if count > 0:# 앞의 기능들과 배포날짜 다름
answer.append(count)
#print(count)
count = 0 # count 초기화
time += 1
print(count,time,answer)
answer.append(count)
return answer
정보가 많아서 도움이 많이 됐습니다.