공부/C#
[프로그래머스] C# 개인정보 수집 유효기간2023 KAKAO BLIND RECRUITMENT
굴러다니다니
2023. 8. 4. 17:29
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
개인정보 수집 유효기간2023 KAKAO BLIND RECRUITMENT Level 1 C#
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(string today, string[] terms, string[] privacies) {
int n = 0;
List<int> answers = new List<int>();
string[] test = today.Split('.'); //년, 월, 일 들어가있음
string[,] termsSplit = new string[terms.Length, 2];
for (int i =0; i < terms.Length; i++){
string[] example = terms[i].Split(' ');
termsSplit[i, 0] = example[0];
termsSplit[i, 1] = example[1];
}
for (int i = 0; i < privacies.Length; i++)
{
string[] privacy = privacies[i].Split(' ');
string[] date = privacy[0].Split('.');
for (int j = 0; j < terms.Length; j++){
if (termsSplit[j, 0] == privacy[1] ) //적합한 종류를 찾았다면
{
int Year = int.Parse(date[0]);
int Month = int.Parse(date[1]) + int.Parse(termsSplit[j, 1]);
int Date = int.Parse(date[2]) -1;
if (Month > 12){
Year += Month / 12;
Month %= 12;
}
if (Month == 0){
Month = 12;
Year -=1;
}
if (Date == 0){
Date = 28;
Month -=1;
}
string[] todaySplit = today.Split('.');
if (int.Parse(todaySplit[0]) > Year || (int.Parse(todaySplit[0]) == Year && int.Parse(todaySplit[1]) > Month) || (int.Parse(todaySplit[0]) == Year && int.Parse(todaySplit[1]) == Month && int.Parse(todaySplit[2]) > Date)) {
answers.Add(i+1);
}
}
}
}
int[] answer = new int[answers.Count];
for ( int i =0; i < answers.Count; i++){
answer[i] = answers[i];
}
return answer;
}
}
Split과 int.Parse 등을 이용해 풀었다.
728x90