개인정보 수집 유효기간

Volc·2023년 4월 6일
0

Algorithm

목록 보기
1/4

문제 접근방법

  • 단순 구현 문제였다.
  • 날짜를 년도,월,일로 나누어 유효기간이 지났는지 안 지났는지 판단 후 answer list에 추가하였다.

코드

def split_terms(terms):
    dic = {}
    for term in terms:
        alpha, day = term.split(' ')
        dic[alpha] = int(day)
    return dic

def solution(today, terms, privacies):
    answer = []
    t_year, t_month, t_day = map(int, today.split('.'))
    t = split_terms(terms)
    
    for i, privacy in enumerate(privacies, start=1):
        date, alpha = privacy.split(' ')
        year, month, day = map(int, date.split('.'))
        month+=t[alpha]
        
        while(month > 12) : 
            month = month-12
            year = year+1
        if t_year > year:
            answer.append(i)
        elif t_year == year:
            if t_month > month:
                answer.append(i)
            elif t_month == month:
                if t_day >= day:
                    answer.append(i)
        
    return answer
profile
미래를 생각하는 개발자

0개의 댓글