프로그래머스 코딩 테스트 문제/lv1

프로래머스 Lv1 유연근무제 문제

lys4321 2026. 2. 24. 13:40
  • 프로래머스 Lv1 유연근무제 문제
    • 해당 문제의 난이도 상승 원인
      • startday을 기준으로 실제 요일을 매핑해야 함
      • 주말은 검사 대상에서 제외
    • 해당 문제를 해결한 방법
      • 24시 초과 대비 % 24 처리
      • 모든 평일을 통과하면 카운트 증가하도록 설정
      • 시작 요일 기준으로 모듈러 연산 적용
    • 문제의 핵심
      • 모듈러 연산 사용
    • 이 문제의 목적
      • 모듈러 연산에 대해서 몰랐다면 학습, 알고있다면 실제 적용법을 학습
class FlexibleWorkSystem {
    public int solution(int[] schedules, int[][] timelogs, int startday){
        int answer = 0;
        // schedules 기준으로 순환
        for(int schedule=0; schedule < schedules.length; schedule++) {
            // 희망 시간 설정
            int hope_time = schedules[schedule] / 100;
            int hope_minute = schedules[schedule] % 100;

            hope_minute += 10; // 먼저 +10
            hope_time = (hope_time + (hope_minute / 60)) % 24; // +10한 후에 목 늘어나면 시간에 +1
            hope_minute = hope_minute % 60; // +10한 후에 나머지 부분만 분으로 설정

            int hope_schedule = (hope_time * 100) + hope_minute;
            int[] access_logs = timelogs[schedule];
            boolean all_complete = true;

            // 대상자 별 출근 이력 순환 및 비교
            for(int i = 0; i < 7; i++) {
                int searchIndex = ((startday - 1 ) + i) % 7;
                // 평일이면서 설정 시간보다 늦게 왔을 경우 체크 감지하여 fasle 변환
                if((searchIndex < 5) && (access_logs[i] > hope_schedule)) {
                    all_complete = false;
                    break;
                }
            }

            if(all_complete) {
                answer++;
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        int[] schedules = {700, 800, 1100};
        int[][] timelogs = {
                {710, 2359, 1050, 700, 650, 631, 659},
                {800, 801, 805, 800, 759, 810, 809},
                {1105, 1001, 1002, 600, 1059, 1001, 1100}
        };
        int startday = 5;

        FlexibleWorkSystem fws = new FlexibleWorkSystem();

        System.out.println("결과 : " + fws.solution(schedules, timelogs, startday));

    }
}