728x90
반응형
문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/92341
풀이:
import math
def get_fee(time, fees):
return fees[1] + math.ceil(max(0, (time - fees[0])) / fees[2]) * fees[3]
def solution(fees, records):
parking = {}
total = {}
for record in records:
time, car, status = record.split()
hour, minute = time.split(":")
minutes = int(hour) * 60 + int(minute)
if status == 'IN': # 들어간 시간
parking[car] = minutes
# elif status == 'OUT': # 나온 시간 출차 - 입차
# if total.get(car):
# total[car] += minutes - total[car]
# else:
# total[car] = minutes - total[car]
elif status == 'OUT':
try:
total[car] += minutes - parking[car]
except:
total[car] = minutes - parking[car]
del parking[car] # 출차 차량 삭제
for car, minute in parking.items():
try:
total[car] += 23 * 60 + 59 - minute
except:
total[car] = 23 * 60 + 59 - minute
return [get_fee(time, fees) for car, time in sorted(list(total.items()), key=lambda x: x[0])] # 차량 번호순으로 정렬
# 친 부분이 되지 않는다 너무 화난다 왜 안되는지 도저히 모르겠다.
다른분의 풀이를 활용했다.
반응형
댓글