728x90

나의 풀이
from collections import defaultdict
def solution(fees, records):
data = defaultdict(list)
answer = []
for record in records:
time, car, io = record.split(' ')
data[car].append(time)
for car, record in sorted(data.items()):
if len(record) % 2:
record.append('23:59')
time = 0
for i in range(0, len(record), 2):
Hi, Mi = record[i].split(':')
Ho, Mo = record[i + 1].split(':')
time += (int(Ho) - int(Hi)) * 60 + (int(Mo) - int(Mi))
if time <= fees[0]:
answer.append(fees[1])
else:
answer.append(fees[1] + ((time - fees[0] + fees[2] - 1) // fees[2]) * fees[3])
return answer
반응형
'Coding Test > Programmers' 카테고리의 다른 글
| [프로그래머스/파이썬] 최솟값 만들기 (0) | 2022.06.20 |
|---|---|
| [프로그래머스/파이썬] 최댓값과 최솟값 (0) | 2022.06.20 |
| [프로그래머스/파이썬] 줄 서는 방법 (0) | 2022.06.20 |
| [프로그래머스/파이썬] 숫자의 표현 (0) | 2022.06.20 |
| [프로그래머스/파이썬] 숫자 블록 (0) | 2022.06.20 |