[파이썬/python] 프로그래머스 : 개인정보 수집 유효기간(Lv.1)

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

def solution(today, terms, privacies):
    dic = {}
    ans = []
    cnt = 0

    today = list(map(int,today.split('.')))
    today = today[0]*12*28 + today[1]*28 + today[2]

    for i in terms:
        dic[i[0]] = int(i[2:])

    for i in privacies:
        cnt += 1
        y,m,d = map(int,(i[:-2].split('.')))
        if y*12*28 + m*28 + d + dic[i[-1]]*28 <= today:
            ans.append(cnt)

    return ans

현재 날짜와 개인정보수집유효기간을 모두 일(day)로 변환한 후에 비교해 주었다.

term을 딕셔너리를 이용하여 dic = {"A":6, "B":12 ...}와 같은 형태로 만들어 주었고,

privacies의 [-1], 즉 약관종류를 dic에서 찾아 28을 곱해주었다.

comment