오구의코딩모험

[Python] 주차 요금 계산 본문

프로그래밍 공부/프로그래머스

[Python] 주차 요금 계산

오구.cpp 2022. 12. 29. 23:34
반응형

 

[2022 KAKAO BLIND RECRUITMENT]

 

from collections import defaultdict
import math
def floor(num):
    if num != int(num):
        return math.ceil(num)
    else:
        return num
        
def time_cal(car_in,car_out="23:59"):
    car_out_h = car_out.split(":")[0]
    car_out_m = car_out.split(":")[1]
    car_in_h = car_in.split(":")[0]
    car_in_m = car_in.split(":")[1]
    
    hour_diff = int(car_out_h)-int(car_in_h)
    min_diff = int(car_out_m)-int(car_in_m)

    return hour_diff*60 + min_diff

def solution(fees, records):
    answer = []
    
    rec_dict = defaultdict(str)
    fee_dict = defaultdict(int)
    for rec in records:
        rec = rec.split()
        if rec_dict[rec[1]] == "":
            rec_dict[rec[1]] = rec[0]
        else:
            time_fee = time_cal(rec_dict[rec[1]], rec[0])
            
            fee_dict[rec[1]] += time_fee
            rec_dict[rec[1]] = ""

    for rec in rec_dict:
        if rec_dict[rec] != "":
            fee_dict[rec] += time_cal(car_in=rec_dict[rec])
            rec_dict[rec] = ""
    
    fee_list = sorted(fee_dict.items(),key=lambda item:item[0])

    return [fees[1]+(floor((cal_fee[1] - fees[0])/fees[2])) * fees[3] if cal_fee[1] > fees[0] else fees[1] for cal_fee in fee_list]
반응형

'프로그래밍 공부 > 프로그래머스' 카테고리의 다른 글

[Python] 더 맵게  (0) 2022.12.30
[Python] 주식가격  (0) 2022.12.30
머쓱이 스탬프 획득!  (0) 2022.12.27
[Python] 기능개발  (0) 2022.12.26
[Python] 올바른 괄호  (0) 2022.12.24
Comments