[프로그래머스 LV1] 2016년

popolarburr·2023년 3월 8일
0
post-thumbnail

- 문제



- 풀이


import java.util.HashMap;
import java.util.Map;

public class Main2 {
    public static void main(String[] args) {
        System.out.println(new Solution().solution(5, 24));
    }
}

class Solution {
    public String solution(int a, int b) {
        Map<Integer, Integer> map = new HashMap<>() {{
            put(1, 31);
            put(2, 29);
            put(3, 31);
            put(4, 30);
            put(5, 31);
            put(6, 30);
            put(7, 31);
            put(8, 31);
            put(9, 30);
            put(10, 31);
            put(11, 30);
            put(12, 31);
        }};

        String[] day = new String[]{ "FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU" };
        int month = 0;

        for (int i = 1; i <= a - 1; i++) {
            month += map.get(i);
        }
        

        return day[(month + b - 1) % 7];
    }
}

- 정리

간단하게 생각하고 풀었는데, 내가 요일을 2월달에 39일로 오타를 내 시간만 버렸다.. 다음부턴 꼼꼼하게 작성하자.




[링크] : 개인저장소

profile
차곡차곡

0개의 댓글