반응형
https://school.programmers.co.kr/learn/courses/30/lessons/92341
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제풀이
from math import ceil
from collections import defaultdict
def solution(fees, records):
history = {}
remainder = defaultdict(int)
fee = {}
d_time, d_fee, u_time, u_fee = fees
for item in records:
time, num, check = item.split()
if check == "IN":
history[num] = convert(time)
else:
remainder[num] += abs(convert(time) - history[num])
history.pop(num)
if history:
for num, time in history.items():
remainder[num] += abs(time - 1439)
for num, time in remainder.items():
if time > d_time:
fee[num] = d_fee + ceil((time - d_time) / u_time) * u_fee
else:
fee[num] = d_fee
return [y for x, y in sorted(fee.items(), key=lambda x: x[0])]
def convert(time):
h, m = time.split(":")
return int(h) * 60 + int(m)