CS/Algorism

[2023 KAKAO BLIND RECRUITMENT] 개인정보 수집 유효기간

olsohee 2024. 2. 27. 11:53

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

 

프로그래머스

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

programmers.co.kr

단순 구현문제이고 레벨 1 문제인데 살짝 헤맸다.. 다른 건 다 간단하고, 주의할 점은 년, 월, 일에 n달을 더하고 비교하는 건데 이를 쉽게 하기 위해 모든 날짜를 일로 변환하면 된다(모든 달은 28일까지 있다고 가정하기 때문에 이렇게 해도 된다). 즉 2022년 1월 1일은 (2022 * 12 * 28) + (1 * 28) + (1)일인 것이다!

import java.util.*;

// 파기해야 할 개인정보 번호를 오름차순으로 
class Solution {

    public int[] solution(String today, String[] terms, String[] privacies) {

        Map<String, Integer> map = new HashMap<>();
        for (String term : terms) {
            String name = term.split(" ")[0];
            Integer date = Integer.parseInt(term.split(" ")[1]);
            map.put(name, date);
        }

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


        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < privacies.length; i++) {
            String[] privacy = privacies[i].split(" ");

            int y = Integer.parseInt(privacy[0].split("\\.")[0]);
            int m = Integer.parseInt(privacy[0].split("\\.")[1]);
            int d = Integer.parseInt(privacy[0].split("\\.")[2]);

            int n = y * 12 * 28 + m * 28 + d + map.get(privacy[1]) * 28;

            // 유효기간이 지났는지 확인
            if (todayNum >= n) {
                list.add(i + 1);
            }
        }

        Collections.sort(list); // 오름차순 정렬
        int[] answer = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            answer[i] = list.get(i);
        }
        return answer;
    }
}

'CS > Algorism' 카테고리의 다른 글

[백준] 1034. 램프  (1) 2024.03.05
[백준] 2493. 탑  (0) 2024.02.29
[2022 KAKAO TECH INTERNSHIP] 등산코스 정하기  (1) 2024.02.13
[백준] 2212. 센서  (1) 2024.02.08
[백준] 1525. 퍼즐  (1) 2024.02.06