Search

개인정보 수집 유효기간

알고리즘
연습문제
플랫폼
프로그래머스
JCF
상태
해결
생성 일시
2023/12/25 07:18
최종 편집 일시
2023/12/26 12:02

문제 설명

해결과정

해결과정

Solution.java

import java.util.*; class Solution { public int[] solution(String today, String[] terms, String[] privacies) { int[] answer = {}; int[] nows = strtointarr(today, "\\."); int year = nows[0]; int month = nows[1]; int day = nows[2]; int now = 0; now += year*10000; now += month*100; now += day; int index = 1; String arrs = ""; // 개인정보 배열 반복 for(String privacy : privacies) { // 공백의 인덱스 값 int spaceIndex = privacy.indexOf(" "); // 가입일 (공백을 기준으로 왼쪽) String accessionDate = privacy.substring(0, spaceIndex++); // 개인정보 약관 (공백을 기준으로 오른쪽) String provision = privacy.substring(spaceIndex, privacy.length()); // 개인정보 보호 기간 int protectionPeriod = findTerms(terms, provision); // 개인정보 파기 날짜 int destructionDate = calcdate(accessionDate, protectionPeriod); if(destructionDate <= now) { arrs += index + " "; // System.out.println("파기"); // System.out.println(accessionDate); // System.out.println(destructionDate); // System.out.println(now); } else { // System.out.println("보관"); // System.out.println(accessionDate); // System.out.println(destructionDate); } index++; } answer = strtointarr(arrs, " "); return answer; } // 문자열 변수 => 문자열 배열 => 정수형 배열 public int[] strtointarr(String str, String rep) { String[] arrs = str.split(rep); int[] nums = new int[arrs.length]; int i = 0; for(String arr : arrs) { nums[i++] = Integer.parseInt(arr); } return nums; } // 개인정보 파기 날짜 계산 public int calcdate(String accessionDate, int protectionPeriod) { int[] dates = strtointarr(accessionDate, "\\."); int year = dates[0] + protectionPeriod/12; int month = dates[1] + (protectionPeriod - (protectionPeriod/12)*12); int day = dates[2]; if(month > 12) { year += 1; month -= 12; } int date = 0; date += year*10000; date += month*100; date += day; return date; } // 개인정보 보호 기간 찾기 public int findTerms(String[] terms, String provision) { int i = 0; for(String term : terms) { if(term.contains(provision)) { int spaceIndex = term.indexOf(" "); String period = term.substring(spaceIndex+1, term.length()); i = Integer.parseInt(period); break; } } return i; } // 문자열 배열 출력 public void arrprint(String str, String[] arrs) { System.out.println("\n" + str); for(String arr : arrs) { System.out.print(arr + " "); } System.out.println(); } // 정수 배열 출력 public void arrprint(String str, int[] arrs) { System.out.println("\n" + str); for(int arr : arrs) { System.out.print(arr + " "); } System.out.println(); } }
Java
복사