Python/프로그래머스

[LV1] 개인정보 수집 유효기간 - 2023 KAKAO BLIND RECRUITMENT

헬로희 2024. 12. 2. 20:19
728x90

Q. 약관 종류에 따른 유효기간이 있고 개인정보 수집일자와 약관종류에 따라 파기해야하는지 아닌지

  • 2000<= YYYY <= 2022
  • 1 <= MM <= 12
  • 1 <= DD <= 28

 

def solution(today, terms, privacies):
    answer = []
    terms_kv ={}
    for term in terms:
        terms_kv[term.split(" ")[0]] = term.split(" ")[1]
    for pr in range(len(privacies)):
        deadline=terms_kv[privacies[pr].split(" ")[1]]
        year=int(today.split(".")[0])-int(privacies[pr].split(" ")[0].split(".")[0])
        month=int(today.split(".")[1])-int(privacies[pr].split(" ")[0].split(".")[1])
        day=int(today.split(".")[2])-int(privacies[pr].split(" ")[0].split(".")[2])
        
        if day<0: 
            month-=1
            day=28+day
        if month<0:
            year-=1
            month=12+month
        r=month*28+day+year*12*28
        a,b=divmod(r, 28)
        if a>=int(deadline): answer.append(pr+1)
        
    return answer

 

map() 함수를 이용해 깔끔하게 가능하니 참고

def to_days(date):
    year, month, day = map(int, date.split("."))
    return year * 28 * 12 + month * 28 + day

def solution(today, terms, privacies):
    months = {v[0]: int(v[2:]) * 28 for v in terms}
    today = to_days(today)
    expire = [
        i + 1 for i, privacy in enumerate(privacies)
        if to_days(privacy[:-2]) + months[privacy[-1]] <= today
    ]
    return expire
728x90