글
C# 개인정보 수집 유효기간
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(string today, string[] terms, string[] privacies) {
List<int> list = new List<int>();
int todayYear = int.Parse(today.Split('.')[0]);
int todayMonth = int.Parse(today.Split('.')[1]);
int todayDay = int.Parse(today.Split('.')[2]);
//.을 기준으로 나누고 int형으로 변환
int todaySum = (todayYear * 12 * 28) + (todayMonth * 28) + todayDay;
// 현재 날짜를 숫자로 표시하기
string[] termsCode = new string[terms.Length];
int[] termsMonth = new int[terms.Length];
for(int i = 0; i < terms.Length; i++)
{
termsCode[i] = terms[i].Split(' ')[0];
// 약관 종류 캐치하기
termsMonth[i] = int.Parse(terms[i].Split(' ')[1]);
// 약관이 몇 개월인지 int형으로 캐치하기
}
for(int i = 0; i < privacies.Length; i++)
{
string[] temp = privacies[i].Split('.', ' ');
// 0 년도 1 월 2 일 3 약관 기호
int year = int.Parse(temp[0]);
int month = int.Parse(temp[1]);
int day = int.Parse(temp[2]);
int num = Array.IndexOf(termsCode, temp[3]);
// 약관 기호가 termsCode 내에 있는 지에 따라 num설정
month += Convert.ToInt32(termsMonth[num]);
// 약관 기호에 적힌 달 수 만큼 플러스를 시킨다.
int sum = (year * 12 * 28) + (month* 28) + day - 1;
// 날짜 수를 체크한다.
if(todaySum > sum)
{
list.Add(i + 1);
// 배열이니까 0부터 시작해서 +1해서 리스트에 넣어주고 ToArray()한다.
}
}
int[] answer = list.ToArray();
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 3진법 뒤집기(int.Parse, 3진수 표기하기) (0) | 2023.01.26 |
---|---|
C# 타겟 넘버(DFS) (0) | 2023.01.26 |
C# 기사단원의 무기(약수) (0) | 2023.01.26 |
프로그래머스 C# 스킬트리(IndexOf) (0) | 2023.01.25 |
프로그래머스 C# 예산(int[]의 Sort) (0) | 2023.01.25 |