IT Study/코딩테스트 by Python

[Programmers로 코테 준비, Python] 코드챌린지 - 유연근무제

짹짹체유 2025. 5. 5. 10:50

 

2025.05.05

 

 

초기 Code

def solution(schedules, timelogs, startday):
    answer = len(schedules)
    checkday = startday
    for i in range(len(schedules)):
        checkday = startday
        for realtime in timelogs[i]:
            if (int(checkday) == 6) or (int(checkday) == 7):
                pass
            else:
                if (realtime//100 > (int(schedules[i])+10)//100):
                    answer -= 1
                    break
            checkday += 1
    return answer

 

  • 문제점 1) checkday가 7을 넘는 경우에 대한 처리 없음
  • 문제점 2) 단순 숫자 연산이 아닌 시분 단위 연산을 고려해야 함 (즉, 60분 이상에 대한 시간 처리)

 

2번째 시도

def solution(schedules, timelogs, startday):
    answer = len(schedules)
    checkday = startday
    for i in range(len(schedules)):
        checkday = startday
        for realtime in timelogs[i]:
            print(checkday)
            if checkday % 7 in [6,0]:
                pass
            else:
                checktime = int(schedules[i])+10
                if (checktime % 100) >= 60:
                    checktime = (int(schedules[i])+100) // 100 * 100
                if (realtime > checktime):
                    answer -= 1
                    break
            checkday += 1
    return answer

 

  • 문제점 1) 여전히 60분 이상에 대한 시간 처리 없음

 

check % in [6, 0]

 

 

 

최종 Code

def solution(schedules, timelogs, startday):
    answer = len(schedules)
    checkday = startday
    for i in range(len(schedules)):
        checkday = startday
        for realtime in timelogs[i]:
            if checkday % 7 in [6,0]:
                pass
            else:
                checktime = int(schedules[i])+10
                if (checktime % 100) >= 60:
                    checktime = ((checktime % 100) - 60 ) + (checktime // 100 + 1) * 100
                if (realtime > checktime):
                    answer -= 1
                    break
            checkday += 1
    return answer

 

 

 

https://school.programmers.co.kr/learn/courses/30/lessons/388351

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

반응형