L1 : 개인정보 수집 유효기간 Python

jhyunn·2023년 1월 11일
0

Programmers

목록 보기
7/69

L1 : 개인정보 수집 유효기간 Python

https://school.programmers.co.kr/learn/courses/30/lessons/150370

def solution(today, terms, privacies):
    
    t = [term.split()[0] for term in terms]
    today_y, today_m, today_d = list(map(int, today.split('.')))
    today = ((today_y-2000)*12+today_m) * 28 + today_d
    answer = []

    for i, p in enumerate(privacies):
        span = int(terms[t.index(p.split()[1])].split()[1])
        start_y, start_m, start_d = list(map(int, p.split()[0].split('.')))
        start = ((start_y-2000)*12+start_m) * 28 + start_d
        
        if today - start >= span*28:
            answer.append(i+1)

    return answer

모든 달이 28일이며, 날짜는 항상 2000-01-01부터인 조건을 활용한다.
today, 시작일 모두 2000-01-01부터 며칠이 지났는지 계산하면
today - 시작일이 가능하다. 이 때의 값이 유효기간보다 긴 지 확인하면 되는 문제.

profile
https://github.com/Sungjeonghyun

0개의 댓글