본문 바로가기
Coding Test/Programmers

[Programmers] 프로그래머스 스택/큐 기능개발 Python 문제풀이

by 챠챠12 2022. 3. 12.

https://programmers.co.kr/learn/courses/30/lessons/42586

 

코딩테스트 연습 - 기능개발

프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는

programmers.co.kr

 

pycharm으로 테스트 해보려고 했던 코드입니다!

import math
def solution(progresses, speeds):
    # 1. 100-93 = 7 7/1 = 7 7일이 걸림 그걸 계산해서 넣기
    left_days = [math.ceil((100 - progresses[i] ) /speeds[i]) for i in range(len(speeds))]

    print(left_days)

    answer = []

    start = left_days[0]
    count = 1
    #  한개 일 때
    if len(left_days) == 1:
        answer = [1]
        return answer
    else:
        # 2. 첫번째랑 두번째 비교해서
        #     1. 비교 > 비교+1 일때까지 비교 후 count+1 하기
        for i in range(1, len(left_days)):
            if start >= left_days[i]:
                count += 1
            else:
                # 정답에 count 넣고, 그 다음 숫자 세기
                answer.append(count)
                start = left_days[i]
                count = 1
        answer.append(count)
        return answer

if __name__ == "__main__":
    progresses = [93, 30, 55]
    speeds = [1, 30, 5]
    result = solution(progresses, speeds)
    print(result)

 

LIST

댓글