-
[프로그래머스] LV1. 개인정보 수집 유효기간알고리즘 2023. 3. 11. 16:03728x90
문제
https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
접근
1. 처음에는 split('.') 사용할 생각을 못하고 year = today[0:4] , month = today[5:7] 이렇게 했는데 코드가 너ㅓㅓㅓ무 더러웠다.
2. 내가 간과한것은 매달이 28일로 "고정" 되어있다 라는 점이다.
3. 그러면 year, month, day를 day 로 전부 바꿔서 합을 구한다음에 privacies 의 값들을 terms의 A인지 B인지 C인지 등등 을 구별해서 각 terms 마다의 month * 28 만큼을 더한 값이 today 보다 크거나 같으면 폐기처분!
=> " EZ " ㅋㅋㅋ풀이
def dateToDay(date): year, month, day = map(int, date.split(".")) return (year * 12 * 28) + (month * 28) + day def MonthToDay(month): return int(month) * 28 def solution(today, terms, privacies): ans = [] todayDays = dateToDay(today) for i in range(len(privacies)): dates, kind = privacies[i].split(' ') date = dateToDay(dates) for term in terms: k, months = term.split(' ') if k == kind: if date + MonthToDay(months) <= todayDays: ans.append(i+1) return ans
'알고리즘' 카테고리의 다른 글
[프로그래머스] LV1. 성격 유형 검사하기 (0) 2023.03.13 [프로그래머스] LV1. 둘만의 암호 (0) 2023.03.13 [프로그래머스] LV1. 기사단원의 무기 (0) 2023.03.11 [프로그래머스] LV1 햄버거 만들기 (0) 2023.03.09 [프로그래머스] LV1. 최소직사각형 (0) 2023.03.09