import math
def convert(time):
hh, mm = time.split(':')
return int(hh)*60 + int(mm)
def solution(fees, records):
intime = {}
result = {}
for x in records:
time, carNum, inout=x.split()
if inout=="IN":
#입고 시간
intime[carNum]=convert(time)
if carNum not in result:
result[carNum]=0
#inout이 "OUT"인 경우
else: #출차시간 #입고시간
result[carNum]+=convert(time)-intime[carNum]
del intime[carNum]
for key, val in intime.items():
#입고 출고가 각각 짝지어 있는 경우에는 intime의 데이터가 지워지기 때문에 intime에 남아 있는 데이터가 없다.
#다만, 입고만 있고, 출고가 없는 경우 11:59분에 출차한것으로 간주하고, 요금을 계산한다.
#val은 intime의 입고시간을 의미한다.
result[key]+=23*60+59 - val
answer = []
for key, val in sorted(result.items()):
#fees[0] : 기본시간
#fees[1] : 기본요금
#fees[2] : 단위시간
#fees[3] : 단위요금
if val <= fees[0]:
answer.append(fees[1])
else:
answer.append(fees[1]+math.ceil((val-fees[0])/ fees[2])*fees[3])
return answer
▶ 사람이 풀 수 있는 건지 모르겠다. 너무 어렵다. 진짜 어렵다.
▶ 파이썬의 split() 함수의 경우 아무것도 안 넣으면, 공백을 기준으로 자른다!!!!!
'프로그래머스(파이썬) > LV.2(파이썬)' 카테고리의 다른 글
피로도 - for문 안에 재귀함수가 있는 경우★★+ return값 없음★ (0) | 2023.01.12 |
---|---|
[3차] 압축 → 전진 + 후진, 슬라이싱 "첫자리" 갱신 (0) | 2023.01.03 |
H-index → 논문을 적게 발표했지만, 인용된 수가 많은 good 케이스 (0) | 2023.01.03 |
더 맵게 → heap★★ (0) | 2023.01.02 |
귤 고르기→ Counter() 함수, most_common() (0) | 2023.01.02 |