eaz_algorithm
[Programmers] 과제 진행하기(Python)
eaz_silver
2024. 7. 2. 17:14
문제
https://school.programmers.co.kr/learn/courses/30/lessons/176962
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
한동안 코테 대비로 파이썬에만 집중해야겠다.
자바스크립트랑 자바는 나중에 다시 채워야지 ㅎㅎㅎ
Python
from collections import deque
def solution(plans):
plans.sort(key=lambda x:x[1])
answer, stack = [], []
n, s, r = plans[0]
p1, p2 = map(int, s.split(':'))
s = p1*60 + p2
stack.append((n, s, int(r)))
for i in range(1, len(plans)):
name, now, time = plans[i]
n1, n2 = map(int, now.split(':'))
start = n1 * 60 + n2
while stack:
pname, pstart, ptime = stack.pop()
if pstart + ptime > start:
stack.append((pname, start, pstart+ptime-start))
break
else:
answer.append(pname)
if stack:
pp1, pp2, pp3 = stack.pop()
stack.append((pp1, pstart+ptime, pp3))
stack.append((name, start, int(time)))
while stack:
a, b, c =stack.pop()
answer.append(a)
return answer