:)
[프로그래머스]주차 요금 계산 본문
https://school.programmers.co.kr/learn/courses/30/lessons/92341
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
구현
1) 차 번호별 시간 구하기(defaultdict)
2) 요금 측정 함수
3) sorted() 차 번호 정렬
from collections import defaultdict
def solution(fees, records):
dic = defaultdict(list)
default_time, default_fee, unit_time, unit_fee = fees
def get_price(log, fees):
if len(log) % 2:
log.append(23*60 + 59)
time = sum(log[i+1] - log[i] for i in range(0, len(log),2))
return unit_fee * -(-max(0,(time - default_time)) // unit_time) + default_fee
for r in records:
time, num, _ = r.split()
h,m = map(int,time.split(':'))
dic[num].append(h*60+m)
return [get_price(dic[i],fees)for i in sorted(dic)]
'Algorithm(python)' 카테고리의 다른 글
[백준] 놀이공원 (0) | 2022.11.21 |
---|---|
[백준]대표선수, [백준]입국심사 (0) | 2022.11.01 |
[백준]겹치는 건 싫어, [백준]회전초밥 (0) | 2022.10.09 |
[프로그래머스]신고 결과 받기, [프로그래머스]양궁대회 (0) | 2022.10.08 |
[프로그래머스]튜플, [프로그래머스]스킬트리 (0) | 2022.10.05 |
Comments