오늘의 취준/오늘의 코테

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

gogoem 2023. 9. 24. 22:41
728x90

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

import java.util.HashMap;
import java.util.ArrayList;
import java.util.Arrays;

class Solution {
    public ArrayList<Integer> solution(String today, String[] terms, String[] privacies) {
        ArrayList<Integer> answer = new ArrayList<Integer>();
        
        HashMap<String, Integer> hash = new HashMap<String, Integer>();
        
        int todayY = Integer.parseInt(today.substring(0, 4));
        int todayM = Integer.parseInt(today.substring(5, 7));
        int todayD = Integer.parseInt(today.substring(8));

        for(String x : terms){
            String termKind = x.substring(0,1);
            int termM = Integer.parseInt(x.substring(2));
            int num = 0, year = 0, month = 0;
            
            if(todayM > termM){
                hash.put(termKind, todayY*10000+(todayM-termM)*100+todayD);
            }else if(todayM == termM){
                hash.put(termKind, (todayY-1)*10000+1200+todayD);
            }else{
                num = todayY*12+todayM-termM;
                if(num%12 == 0){
                    month = 12;
                    year = num / 12 - 1;
                }else{
                    month = num % 12;
                    year = num / 12;
                }
                hash.put(termKind, year*10000+month*100+todayD);
            }
        }
        
        for(int i = 0; i<privacies.length; i++){
            String x = privacies[i];
            int priDate = Integer.parseInt(x.substring(0, 4))*10000+Integer.parseInt(x.substring(5, 7))*100+Integer.parseInt(x.substring(8, 10));
            String tKind = x.substring(x.length() - 1);
            System.out.println(hash.get(tKind) + " " + priDate);
            if(hash.get(tKind) >= priDate){
                answer.add(i+1);
            }
        }
        return answer;
    }
}