요구사항

일주일의 이벤트 기간동안 직원들은 각자 설정한 출근 희망 시각에 +10분까지 출근해야 한다고 할때

일주일 동안 주말(토, 일) 제외 한번도 늦지 않은 직원의 수를 구하기

 

 

입력 값

int[] schedules 직원들의 출근 희망 시각을 담은 hhmm 형식의 숫자 배열
schedules[i] 는 i+1 번째 직원의 출근 희망 시각
int[][] timelogs 직원들의 이벤트 시작일로부터 일주일 간 출근 기록
timelogs[i] 는 i+1 번째 직원의 일주일 출근 기록을 저장한 숫자  배열
timelogs[i][j] 는 i+1 번째 직원의 j+1 번째 일자의 hhmm 형태의 출근 시간
int startday 이벤트 시작 요일
1 월요일, 2 화요일, 3 수요일, 4 목요일, 5 금요일, 6 토요일, 7 일요일

 

 

풀이

1. 직원들의 모든 출근일을 확인하기 위해 loop

 

2. 직원이 설정한 출근 희망 시간과 실제 출근 시간 비교
   -> 출근 일자가 토요일이나 일요일인 경우 비교 대상 제외

   -> 출근 희망 시간 + 10분 보다 늦게 출근 한 경우 break 하고 카운팅 하지 않음

 

728x90

 

Java 코드

class Solution {
    public int solution(int[] schedules, int[][] timelogs, int startday) {
        int answer = 0;
        
        boolean isFail;
        
        for(int i=0; i<schedules.length; i++) {
            isFail = false;
            for(int j=0; j<7; j++) {
                // 토, 일 체크 제외
                if((startday + j)%7 == 6 || (startday + j)%7 == 0) continue;
                
                if(schedules[i] + (schedules[i]%100 >= 50 ? 50 : 10) < timelogs[i][j]) {
                    isFail = true;
                    break;
                }
            }
            if(!isFail) answer++;
        }
    
        return answer;
    }
}

 

 

문제 출처

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

728x90
반응형

+ Recent posts