문제 설명
고객의 약관 동의를 얻어서 수집된 1~n번으로 분류되는 개인정보 n개가 있습니다. 약관 종류는 여러 가지 있으며 각 약관마다 개인정보 보관 유효기간이 정해져 있습니다. 당신은 각 개인정보가 어떤 약관으로 수집됐는지 알고 있습니다. 수집된 개인정보는 유효기간 전까지만 보관 가능하며, 유효기간이 지났다면 반드시 파기해야 합니다.
예를 들어, A라는 약관의 유효기간이 12 달이고, 2021년 1월 5일에 수집된 개인정보가 A약관으로 수집되었다면 해당 개인정보는 2022년 1월 4일까지 보관 가능하며 2022년 1월 5일부터 파기해야 할 개인정보입니다.
당신은 오늘 날짜로 파기해야 할 개인정보 번호들을 구하려 합니다.
모든 달은 28일까지 있다고 가정합니다.
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(string today, string[] terms, string[] privacies) {
List answer = new List();
DateTime Dttoday = Convert.ToDateTime(today); // 날짜 DateTime으로 변환
Dictionary<string, int> dicterms = new Dictionary<string, int>();
foreach (string item in terms)
{
string[] a = item.Split(' '); //공백으로 쪼개기
dicterms.Add(a[0], Convert.ToInt32(a[1])); //dictionary에 담기
}
int seq = 1;
foreach (string item in privacies)
{
string[] a = item.Split(' '); //공백으로 쪼개기
DateTime b = Convert.ToDateTime(a[0]);
if(b.AddMonths(dicterms[a[1]]).AddDays(-1).CompareTo(Dttoday) < 0) //유효기간을 더한 날짜와 today 비교
{
answer.Add(seq);
}
seq++;
}
return answer.ToArray();
}
}
'코딩연습 > 프로그래머스 코딩테스트' 카테고리의 다른 글
[프로그래머스] 완전탐색 - 카펫 (0) | 2022.11.15 |
---|---|
[프로그래머스] 완전탐색 - 직사각형 (0) | 2022.11.14 |
Lv1. 과일장수 (0) | 2022.11.14 |
[프로그래머스]기능개발 (0) | 2021.05.09 |
[프로그래머스] 핸드폰 번호 가리기 (0) | 2021.05.09 |