난이도: 중하 

날짜에 관해 조금이라도 다뤄봤다면 해결가능한 문제이다.

 

 

class Solution {
    public String solution(int a, int b) {
        String answer = "";
        int [] date = {31,29,31,30,31,30,31,31,30,31,30,31};
        String [] day = {"FRI","SAT","SUN","MON","TUE","WED","THU"};
        
        int selected = 0;// 5월 24일을 며칠인지 숫자로 바꾸는 작업
        for(int i = 0; i < a-1; i++){ // 해당 달의 date는 더하면 안되기 때문에 a-1까지
            selected += date[i];
        }
        
        selected += b-1;//index가 0에서 시작되니까 1씩 빼준다. 1월 1일이 하루가 지난날이 아니기 때문이다
        answer = day[selected%7];
        
        
        return answer;
    }
}

 

 

https://programmers.co.kr/learn/courses/30/lessons/12901

'알고리즘문제 > Programmers' 카테고리의 다른 글

수박수박~  (0) 2022.07.15

+ Recent posts