728x90
https://programmers.co.kr/learn/courses/30/lessons/92341
import math
def solution(fees, records):
records = [i.split() for i in records]
records.sort(key=lambda x:x[1])
time, car = records[0][0], records[0][1]
flag = 1
car_dict = {}
for i in range(1, len(records)):
if records[i][2] == 'IN':
if flag == 1:
time_in = time.split(':')
time_out = '23:59'.split(':')
time_total = 0
if int(time_out[1]) >= int(time_in[1]):
time_total = (int(time_out[0])-int(time_in[0]))*60 + (int(time_out[1])-int(time_in[1]))
else:
time_total = (int(time_out[0])-1-int(time_in[0]))*60 + (60+int(time_out[1])-int(time_in[1]))
# car_dict 에 누적 주차 시간 변경
if car not in car_dict:
car_dict[car] = time_total
else:
car_dict[car] += time_total
car = records[i][1]
time = records[i][0]
flag = 1 # 입차
else:
car = records[i][1]
time = records[i][0]
flag = 1 # 입차
else:
if records[i][1] == car:
flag = 0 # 출차
time_in = time.split(':')
time_out = records[i][0].split(':')
time_total = ''
if int(time_out[1]) >= int(time_in[1]):
time_total = (int(time_out[0])-int(time_in[0]))*60 + (int(time_out[1])-int(time_in[1]))
else:
time_total = (int(time_out[0])-1-int(time_in[0]))*60 + (60+int(time_out[1])-int(time_in[1]))
# car_dict 에 누적 주차 시간 변경
if car not in car_dict:
car_dict[car] = time_total
else:
car_dict[car] += time_total
if flag == 1:
time_in = time.split(':')
time_out = '23:59'.split(':')
time_total = 0
if int(time_out[1]) >= int(time_in[1]):
time_total = (int(time_out[0])-int(time_in[0]))*60 + (int(time_out[1])-int(time_in[1]))
else:
time_total = (int(time_out[0])-1-int(time_in[0]))*60 + (60+int(time_out[1])-int(time_in[1]))
# car_dict 에 누적 주차 시간 변경
if car not in car_dict:
car_dict[car] = time_total
else:
car_dict[car] += time_total
# 결과
answer = []
for car, time in car_dict.items():
if fees[1] + math.ceil((time-fees[0])/fees[2])*fees[3] < fees[1]:
answer.append(fees[1])
else:
answer.append(fees[1] + math.ceil((time-fees[0])/fees[2])*fees[3])
return answer
머리가 터지는 줄 알았다..
반응형
'전.py' 카테고리의 다른 글
[python] 프로그래머스 체육복 (Lv.1) (0) | 2022.02.15 |
---|---|
[python] 백준 1166 선물 (0) | 2022.02.15 |
[python] 백준 17626 Four Squares (0) | 2022.02.14 |
[python] 백준 1764 듣보잡 (0) | 2022.02.14 |
[python] 백준 1676 팩토리얼 0의 개수 (0) | 2022.02.14 |