[프로그래머스] 개인정보 수집 유효기간

JinUk Lee·2023년 2월 16일
0

프로그래머스

목록 보기
16/47

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


def solution(today, terms, privacies):
    answer = []
    term_dict = dict()
    today_year,today_month,today_day = map(int,today.split('.')) # 오늘 날짜를 년,월,일로 분리하고 int형으로 변환
    idx = 1 
    

    for t in terms:
        alp,num = t.split()
        term_dict[alp] = int(num) # terms를 딕셔너리로 변환
        
    term_alp = list(term_dict.keys()) # term의 키값만 가져옴
    
    for pri in privacies:
        priday,term = pri.split()
        year,month,day = map(int,priday.split('.'))
        for alp in term_alp:
            if term ==alp:
                month+=term_dict[alp]
                while True:
                    
                    if month >12:
                        year+=1
                        month = month-12
                    else:
                        break
        
        if today_year > year:
            answer.append(idx)

        elif (year==today_year) and (today_month>month):
            answer.append(idx)
        elif (year==today_year) and (today_month==month) and (today_day>=day):
        # 보관기간이 그 전날까지이므로 둘이 날짜가 같으면 파기한다.
            answer.append(idx)            

        idx+=1
    
        
    return answer

레벨 1 문제치고는 상당히 복잡했던 문제였다.

profile
개발자 지망생

0개의 댓글