Algorithm/problems

프로그래머스, 개인정보 수집 유효기간 (Python)

수밈 2023. 6. 21. 23:54

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

 

프로그래머스

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

programmers.co.kr

 

## Problem

 

유효기간이 지난 date 의 idx 를 출력하면 되는 문제당. 처음에는 timestamp 를 사용해서 바꿨지만, 여기에서 날짜는 28일로 고정한다는 말에 조금 애 먹었다. 

검색의 도움을 받았고, timstamp 를 직접 만드는 형식으로 진행하길래 변경하였다.

 

 

## Solved

def solution(today, terms, privacies):
    answer = []
    terms = {term.split()[0]:int(term.split()[1])*28 for term in terms}
    return [idx + 1
     for idx, privacy in enumerate(privacies) 
     if to_day(privacy.split(" ")[0]) + terms[privacy.split(" ")[1]] <= to_day(today)
    ]


def to_day(t) :
    year, month, day = map(int, t.split('.'))
    return year * 12 * 28 + month * 28 + day