Search
Duplicate

개인정보 수집 유효기간

문제 설명 및 제한사항

아이디어 및 해결 방법

코드

DAYS_IN_MONTH = 28 DAYS_IN_YEAR = 12 * DAYS_IN_MONTH def add_month(y, m, d, monthdiff): day = (y - 1) * DAYS_IN_YEAR + (m - 1) * DAYS_IN_MONTH + d daydiff = monthdiff * 28 - 1 day += daydiff new_y, r = (day // DAYS_IN_YEAR) + 1, day % DAYS_IN_YEAR new_m, r = (r // DAYS_IN_MONTH) + 1, r % DAYS_IN_MONTH new_d = r return new_y, new_m, new_d def after(y_a, m_a, d_a, y_b, m_b, d_b): if y_a > y_b: return True elif y_a == y_b: if m_a > m_b: return True elif m_a == m_b: if d_a > d_b: return True return False def solution(today, terms, privacies): y_tod, m_tod, d_tod = map(int, today.split('.')) term2monthdiff = {} for token in terms: term, monthdiff = token.split() monthdiff = int(monthdiff) term2monthdiff[term] = monthdiff answer = [] for i, token in enumerate(privacies, 1): date, term = token.split() y, m, d = map(int, date.split('.')) print(add_month(y, m, d, term2monthdiff[term])) if after(y_tod, m_tod, d_tod, *add_month(y, m, d, term2monthdiff[term])): answer.append(i) return answer
Python
복사

출처

프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges