자료구조, 알고리즘/파이썬
[프로그래머스] 유연근무제
heehminh
2025. 7. 1. 19:04
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/388351
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
풀이
1. 출근 마지노선 시간 구하기
출근 희망 시각이 7:30처럼 10분을 더해도 문제없으면 그냥 10분 더해줌
단, 8시 55분처럼 10분을 더했을때 시간이 넘어가는 경우에는 별도의 조치가 필요함
dead_time = schedules[i] + 10
if (schedules[i] + 10)%100 >= 60:
dead_time = schedules[i] + 10 - 60 + 100
865 % 100 = 65 처럼 10분을 더했을 때 60분 이상인 경우엔
60분을 빼주고 1시간을 더해줌
따라서 출근 희망 시각 + 10분 - 60분 + 100 (1시간)
2. 요일 처리
day += 1
if day > 7:
day = 1
출근 마지노선까지 출근했는지 확인하고 요일 +1
단순하게 요일이 7 초과면 요일을 1로 초기화
3. 이벤트 증정 여부
isPass = True
for time in timelogs[i]:
if day not in [6,7] and time > dead_time:
isPass = False
break
if isPass:
answer += 1
반복문 시작 전 플래그를 세우고
요일이 토, 일이 아닌데 출근 마지노선 시간보다 출근 시간이 늦은 경우 플래그를 False로 설정
반복문을 끝까지 돌았을 때 플래그가 True라면 이벤트 증정 (answer +1)
전체 코드
def solution(schedules, timelogs, startday):
answer = 0
for i in range(len(schedules)):
dead_time = schedules[i] + 10
if (schedules[i] + 10)%100 >= 60:
dead_time = schedules[i] + 10 - 60 + 100
day = startday
isPass = True
for time in timelogs[i]:
if day not in [6,7] and time > dead_time:
isPass = False
break
day += 1
if day > 7:
day = 1
if isPass:
answer += 1
return answer
반응형