그냥 어려울 것 없는 구현 문제
과거의 나는 뭐 저래 풀었담.. 과거 시간 계산하기 귀찮아서 datetime 보고 막하느라 엄청 오래걸렸던 것 기억남. 반대로 이제는 그거 찾아보기 귀찮아서 그냥 내가 함수 만드는 게 더 편함
주석처리 = 과거
import math
def timeCal(a,b):
a= list(map(int, a.split(':')))
b= list(map(int, b.split(':')))
h = a[0] - b[0]
if a[1] < b[1]:
h -= 1
m = a[1] + 60 - b[1]
else: m = a[1] - b[1]
return h*60 + m
def fee(time,fees):
if time <= fees[0]: return fees[1]
else:
time -= fees[0]
return fees[1] + math.ceil(time/fees[2]) * fees[-1]
def solution(fees, records):
answer = []
recordsDic = {}
for r in records:
temp = r.split()
if temp[1] in recordsDic: recordsDic[temp[1]].append(temp[0])
else: recordsDic[temp[1]] = [temp[0]]
recordsDic = sorted(recordsDic.items())
for car,time in recordsDic:
if len(time) % 2 == 1: time.append('23:59')
tempTime = 0
while time:
a = time.pop()
b = time.pop()
tempTime += timeCal(a,b)
answer.append(fee(tempTime,fees))
return answer
# import datetime
# def solution(fees, records):
# answer = []
# dic ={}
# for i in records:
# time, car_n, bd = i.split(' ')
# if car_n in dic:
# temp = dic.get(car_n)
# temp.append(time)
# else:
# dic[car_n] = [time]
# for k,li_ in dic.items():
# time = datetime.datetime.strptime('00:00',"%H:%M")
# while li_:
# if len(li_) %2 == 1 :
# time_1 = datetime.datetime.strptime('23:59',"%H:%M")
# time_2 = datetime.datetime.strptime(li_.pop(),"%H:%M")
# time = time_1 - time_2
# else:
# time_1 = datetime.datetime.strptime(li_.pop(),"%H:%M")
# time_2 = datetime.datetime.strptime(li_.pop(),"%H:%M")
# time_temp = time_1 - time_2
# time = time + time_temp
# time= str(time)
# time = time[-8:]
# h,m,s =map(int, time.split(':'))
# base = h*60 + m
# if base <= fees[0]:
# dic[k] = fees[1]
# else:
# time =h*60 + m - fees[0]
# if time%fees[2] == 0:
# dic[k] = fees[1] + (time//fees[2])*fees[3]
# else:
# dic[k] = fees[1] + (time//fees[2]+1)*fees[3]
# dic_sort = sorted(dic.items())
# for i in range(len(dic)):
# a= list(dic_sort[i])
# answer.append(a[1])
# return answer