728x90
반응형
using System;
using System.Collections.Generic;
public class Solution
{
public List<int> solution(string today, string[] terms, string[] privacies)
{
List<int> answerList = new List<int>();
DateTime D_today = DateTime.Parse(today); // 오늘 날짜
Dictionary<string, int> termsDict = new Dictionary<string, int>(); // terms를 받을 딕셔너리 (유효기간 비교용)
//알파벳을 키 값, 유효기간을 밸류값으로
for (int i = 0; i < terms.Length; i++) // 딕셔너리 값 넣어주기
{
string[] termInfo = terms[i].Split(' '); // 스페이스 기준으로 자르기
termsDict.Add(termInfo[0], int.Parse(termInfo[1])); // dict에는 유효기간 개월수를 넣기, string 값이므로 비교하기 편하게 int로 변환
}
for (int i = 0; i < privacies.Length; i++) // 입력값 길이 만큼 개인정보 하나씩 비교
{
DateTime D_Privacies = DateTime.Parse(privacies[i].Split(' ')[0]); // 첫 개인정보 수집 일자를 DateTime으로 받아오고
int termMonths = termsDict[privacies[i].Split(' ')[1]]; // 비교할 기준 개월수를 딕셔너리에서 가져오고
DateTime D_Expire = D_Privacies.AddMonths(termMonths); // 받아온 날짜에서 기준 개월수만큼 유효기간 달 수를 더해줌
if (D_today >= D_Expire) // 오늘 날짜가 기준 개월수를 초과 하는지 안하는지 비교 (파기 여부 결정)
{
answerList.Add(i + 1);
}
}
return answerList;
}
}
728x90
반응형
'코딩테스트' 카테고리의 다른 글
C# [프로그래머스] Lv.1 숫자 짝꿍 (0) | 2024.02.05 |
---|---|
C# [프로그래머스] Lv.1 과일 장수 (1) | 2023.12.28 |
C# [프로그래머스] Lv.1 카드 뭉치 (0) | 2023.12.26 |
C# [프로그래머스] Lv.1 덧칠하기 (0) | 2023.12.26 |
[프로그래머스] Lv.0 문자열 반복 출력 하기 (0) | 2023.11.08 |