🐣 알고리즘 삐약/✏️ 냅다 덤벼보는 문제풀이

[프로그래머스] LV.1 개인정보 수집 유효기간 | JAVA

우주수첩 2024. 8. 15. 14:58
728x90

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

static ArrayList<Integer> solution(String today, String[] terms, String[] privacies) {
        ArrayList<Integer> answer = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();

        for(String str : terms){
            map.put(str.split(" ")[0],Integer.parseInt(str.split(" ")[1]));
        }

        int t_year = Integer.parseInt(today.split("\\.")[0])*12*28;
        int t_month = Integer.parseInt(today.split("\\.")[1])*28;
        int t_day = Integer.parseInt(today.split("\\.")[2]);
        int t_total = t_year+t_month+t_day;

        for(int i=0;i<privacies.length;i++){
            int ep = map.get(privacies[i].split(" ")[1])*28-1;
            String enrollment = privacies[i].split(" ")[0];

            int year = Integer.parseInt(enrollment.split("\\.")[0])*12*28;
            int month = Integer.parseInt(enrollment.split("\\.")[1])*28;
            int day = Integer.parseInt(enrollment.split("\\.")[2]);

            if(t_total > year+month+day+ep){
                answer.add(i+1);
            }

        }



        return answer;
    }
728x90