https://school.programmers.co.kr/learn/courses/30/lessons/92341
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
오랜만에 다시 풀었는데 예전 코드랑 거의 비슷해서 신기했다.
from collections import defaultdict
from collections import deque
import math
def solution(fees, records):
answer = []
rd = defaultdict(list) # records dict
for record in records:
t, n, s = record.split(' ')
rd[n].append([(int(t[:2])*60 + int(t[3:])), s])
rd = dict(sorted(rd.items()))
for k, v in rd.items():
inout = deque()
value = 0
for v_ in v:
if v_[1] == 'IN':
inout.append(v_[0])
else:
value += v_[0] - inout.popleft()
else:
if inout:
value += 1439 - inout.popleft()
if value <= fees[0]:
answer.append(fees[1])
else:
answer.append(fees[1] + math.ceil((value-fees[0])/fees[2])*fees[3])
return answer
'Coding Test > 프로그래머스' 카테고리의 다른 글
[프로그래머스] / [Level 2] / [Python] k진수에서 소수 개수 구하기 (0) | 2023.03.20 |
---|---|
[프로그래머스] / [Level 2] / [Python] [3차] 압축 (0) | 2023.03.20 |
[프로그래머스] / [Level 2] / [Python] 리코쳇 로봇 (0) | 2023.03.19 |
[프로그래머스] / [Level 1] / [Python] 삼총사 (0) | 2023.03.10 |
[프로그래머스] / [Level 1] / [Python] 크기가 작은 부분 문자열 (0) | 2023.03.10 |