💡 코테/99클럽

[ 99클럽 코테 스터디 18일차 TIL ] 프로그래머스(개인정보 수집 유효기간)

MNY 2024. 4. 15. 22:43
728x90
반응형
💡 오늘의 학습 키워드

- 프로그래머스
    * 개인정보 수집 유효기간 : 미들러 문제(Level 2)

 

오늘의 회고

문제1  : [개인정보 수집 유효기간]

  • 어떤 문제가 있었고, 나는 어떤 시도를 했는지

오늘의 날짜와 개인정보 수집 날짜 그리고 유효기간(월)을 알려주었을 때 폐기해야 하는 개인정보 번호를 리턴해주는 문제였다.

 

우선, split해야 하는 문제가 너무 많아서 당황했다.

이걸 어떻게 풀지? 어떻게 나누지? 라고 생각했지만..

그래도 일단 공백, "\\."을 기준으로 문자열을 나누었다.

  • 오늘의 년,월,일
  • 유효기간 타입, 기간
  • 개인정보들의 수집날짜, 유효기간 타입

이렇게 데이터를 정리해줬다.

 

반복문을 돌며

  • 개인정보들의 수집날짜를 년,월,일로 다시 나누어주고
  • 개인정보 유효 마감일을 구하고
  • 오늘의 날짜가 개인정보 유효 마감일보다 뒤라면 폐기할 정보로 넣어줬다.

 

그러고 배열 크기 맞추려고..

무식하게 반복문을 사용했다. 

 

 

프로그래머스

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

programmers.co.kr

 

  • 어떻게 해결했는지
import java.util.*;

class Solution {
    public String[][] arrSplit(String[] arr) {
        int size = arr.length;
        String[][] arrSplit = new String[size][2];
        
        for (int i = 0; i < size; i++) {
            arrSplit[i] = arr[i].split(" ");
        }
        
        return arrSplit;
    }
    
    public String[] findDeadline(String[] day, String[][] termsArr, int termSize) {
        int month = 0;
        String[] tempDay = day[0].split("\\.");
        
        for (int i = 0; i < termSize; i++) {
            if (day[1].equals(termsArr[i][0])){
                month = Integer.parseInt(termsArr[i][1]);
            }
        }
        
        
        tempDay[1] = Integer.toString(Integer.parseInt(tempDay[1]) + month);
        while (Integer.parseInt(tempDay[1]) > 12) {
            tempDay[0] = Integer.toString(Integer.parseInt(tempDay[0]) + 1);
            tempDay[1] = Integer.toString(Integer.parseInt(tempDay[1]) - 12);
        }
        
        return tempDay;
    }
    
    public boolean checkDeadline(String[] today, String[] deadline) {
        if (Integer.parseInt(today[0]) > Integer.parseInt(deadline[0]))
            return true;
        else if (Integer.parseInt(today[0]) == Integer.parseInt(deadline[0])
                && Integer.parseInt(today[1]) > Integer.parseInt(deadline[1]))
            return true;
        else if (Integer.parseInt(today[0]) == Integer.parseInt(deadline[0])
                && Integer.parseInt(today[1]) == Integer.parseInt(deadline[1])
                && Integer.parseInt(today[2]) >= Integer.parseInt(deadline[2]))
            return true;
        return false;
    }
    
    public int[] solution(String today, String[] terms, String[] privacies) {
        int privSize = privacies.length;
        int termSize = terms.length;
        int[] temp = new int[privSize];
        String[] todayArr = today.split("\\.");
        String[][] termsArr = new String[termSize][2];
        String[][] privArr = new String[privSize][2];
        
        termsArr = arrSplit(terms);
        privArr = arrSplit(privacies);
        

        for (int i = 0; i < privSize; i++) {
            String[] deadline = findDeadline(privArr[i], termsArr, termSize);
            if(checkDeadline(todayArr, deadline)){
                temp[i] = i+1;
                
            }
        }

        int size = 0;
        for (int i = 0; i < privSize; i++) {
            if (temp[i] != 0)
                size++;
        }
        
        
        int idx = 0;
        int[] answer = new int[size];
        for (int i = 0; i < privSize; i++) {
            if (temp[i] != 0) {
                answer[idx] = temp[i];
                idx++;
            }
        }

        return answer;
    }
}

 

  • 무엇을 새롭게 알았는지

split에 대해 배웠다.. 자바는 형변환 함수가 너무 길고해서 split함수가 있는지 몰랐는데..

이건 또 있어서 나름? 편했다.

오늘 내배캠(9-9) 첫 날이라 너무 피곤해서 split 함수 정리를 못하겠다ㅠ

언젠가 기억나거나 다시 또 쓸일 있으면 그 때 정리해야지

 

내일 학습할 것은 무엇인지 (최대 3개)

  • 정보처리기사 실기
  • 자바 형변환 정리
  • 클럽99 코딩테스트(미들러)
728x90
반응형