일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 정규식
- 파이썬
- python
- lambda
- 이분탐색
- 백준
- programmers
- 위클리 챌린지
- dfs
- 동적 계획법
- 자바
- 카카오
- divmod
- 재귀함수
- java
- 프로그래머스
- 정렬
- KAKAO BLIND RECRUITMENT
- BFS
- DateTime
- 수학
- Combinations
- Zip
- 다익스트라
- Re
- heapq
- backjoon
- 그리디
- 추석맞이 코딩챌린지
- Set
Archives
- Today
- Total
상상쓰
[프로그래머스] 주차 요금 계산 본문
https://programmers.co.kr/learn/courses/30/lessons/92341
코딩테스트 연습 - 주차 요금 계산
[180, 5000, 10, 600] ["05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"] [14600, 34400, 5000]
programmers.co.kr
오랜만에 풀어서 그런지 문법들이 기억이 잘 안 난다.
dictionary 를 이용하여 입차 시간과 출차 될 때 주차시간을 기록한다.
import math
def solution(fees, records):
answer = []
dic = {}
last_time = 23 * 60 + 59
for i in records:
time, car, history = i.split(' ')
h, m = time.split(':')
time = int(h) * 60 + int(m)
if history == 'IN':
if car not in dic:
dic[car] = [time, 0]
else:
dic[car] = [time, dic[car][1]]
else:
dic[car] = [-1, dic[car][1] + time - dic[car][0]]
cars = sorted(dic.keys())
for i in cars:
mm = dic[i][1]
if dic[i][0] >= 0:
mm = mm + last_time - dic[i][0]
answer.append(fees[1] + math.ceil(max(0, mm - fees[0]) / fees[2]) * fees[3])
return answer
print(solution([180, 5000, 10, 600], ['05:34 5961 IN', '06:00 0000 IN', '06:34 0000 OUT', '07:59 5961 OUT', '07:59 0148 IN', '18:59 0000 IN', '19:09 0148 OUT', '22:59 5961 IN', '23:00 5961 OUT']) # [14600, 34400, 5000]
'Coding Test' 카테고리의 다른 글
[백준] 숫자고르기 (0) | 2022.02.27 |
---|---|
[프로그래머스] 양궁대회 (0) | 2022.02.20 |
[프로그래머스] k진수에서 소수 개수 구하기 (0) | 2022.01.23 |
[프로그래머스] 신고 결과 받기 (0) | 2022.01.19 |
[백준] Fly me to the Alpha Centauri (2) | 2022.01.14 |
Comments