본문 바로가기
프로그래머스/lv.1

개인정보 수집 유효기간

by bingual 2024. 1. 30.
반응형

 

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

 

프로그래머스

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

programmers.co.kr

문제풀이

TTL을 초 단위로 변환하여 계산 하는거 처럼 각 날짜를 일 단위로 변환하여 계산할 수 있다.

def solution(today, terms, privacies):
    answer = []

    today = day_convert(today)
    term = {key: int(value) for key, value in (term.split() for term in terms)}

    for i, privacy in enumerate(privacies):
        date, key = privacy.split()  # 수집 일자, 약관 종류 분리
        current = day_convert(date) + term[key] * 28  # 수집 일자에 n개월 만큼을 더함

        if current <= today:
            answer.append(i + 1)

    return answer


# 날짜의 단위를 일로 변환
def day_convert(today):
    year, month, day = map(int, today.split("."))
    return (year * 12 * 28) + (month * 28 + day)

'프로그래머스 > lv.1' 카테고리의 다른 글

[PCCP 기출문제] 1번 / 붕대 감기  (0) 2024.01.31
신고 결과 받기  (1) 2024.01.31
[PCCE 기출문제] 10번 / 데이터 분석  (0) 2024.01.30
성격 유형 검사하기  (0) 2024.01.30
둘만의 암호  (0) 2024.01.29