from collections import defaultdict
import math
def solution(fees, records):
answer = []
statusDict, timeDict = defaultdict(lambda: False), defaultdict(lambda: 0)
resultDict = defaultdict(lambda: 0)
for record in records:
time, carNum, status = record.split(" ")
hr, m = map(int, time.split(":"))
getTime = hr*60 + m
# IN
if statusDict[carNum] == False and status == "IN":
statusDict[carNum] = True
timeDict[carNum] += getTime
# OUT
elif statusDict[carNum] and status == "OUT":
statusDict[carNum] = False
timeDiff = getTime - timeDict[carNum]
resultDict[carNum] += timeDiff
timeDict[carNum] = 0
# IN, 하지만 자정까지 OUT 기록은 없는 경우
for items, values in statusDict.items():
if values:
maxTime = 23*60 + 59
resultDict[items] += maxTime - timeDict[items]
# 주차 요금 환산
nTime, nFee, perTime, perFee = map(int, fees)
for i,v in sorted(resultDict.items()):
totalPrice = 0
# 기본 시간 초과
if v > nTime:
v -= nTime
totalPrice += nFee
totalPrice += math.ceil(v/perTime)*perFee
else:
totalPrice += nFee
answer.append(totalPrice)
return answer
프로그래머스 연습문제: https://school.programmers.co.kr/learn/challenges