https://school.programmers.co.kr/learn/courses/30/lessons/92341
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제


내 풀이
def solution(fees, records):
total_fees = {}
car_num_list = []
time_list = []
for parking in records:
time_cal, car_num, types = parking.split()
h, m = time_cal.split(":")
time = int(h) * 60 + int(m)
if types == 'IN':
car_num_list.append(car_num)
time_list.append(time)
elif types == 'OUT':
if car_num in total_fees:
total_fees[car_num] = total_fees[car_num] + (time - time_list.pop(car_num_list.index(car_num)))
else:
total_fees[car_num] = (time - time_list.pop(car_num_list.index(car_num)))
car_num_list.remove(car_num)
if car_num_list: # 만약 아직 출차하지 않은 차량이 있다면
for i in range(len(car_num_list)):
if car_num_list[i] in total_fees:
total_fees[car_num_list[i]] = total_fees[car_num_list[i]] + ((23*60+59) - time_list[i])
else:
total_fees[car_num_list[i]] = ((23*60+59) - time_list[i])
basic_min, basic_fee, per_min, per_fee = fees
for key, value in total_fees.items():
if value <= basic_min:
total_fees[key] = basic_fee
else:
if ((value - basic_min) % per_min) != 0:
total_fees[key] = basic_fee + (((value - basic_min) // per_min)+1) * per_fee
else:
total_fees[key] = basic_fee + ((value - basic_min) // per_min) * per_fee
answer = []
sorted_dict = sorted(total_fees.items(), key = lambda item: item[0])
for key, value in sorted_dict:
answer.append(value)
return answer
fees = [1, 461, 1, 10]
records = ["00:00 1234 IN"]
solution(fees, records)
메모
프로그래머스 Lv2. 문제2022 KAKAO BLIND RECRUITMENT 문제
'파이썬 알고리즘 연습' 카테고리의 다른 글
[Python | 백준 18110번] solved.ac (0) | 2024.06.30 |
---|---|
[Python | 백준 2164번] 카드2 (0) | 2024.06.27 |
[Python | 프로그래머스] 가장 많이 받은 선물 (1) | 2024.06.11 |
[Python | 백준 1783번] 병든 나이트 (0) | 2024.04.23 |
[Python | 백준 11478번] 서로 다른 부분 문자열의 개수 (0) | 2024.04.23 |