DecordRay

[프로그래머스] Level1 : 개인정보 수집 유효기간[Python] 본문

알고리즘/프로그래머스

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

DecordRay 2023. 2. 6. 23:04
728x90
반응형

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

 

프로그래머스

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

programmers.co.kr

 

풀이 :

1. 딕셔너리, 변수

  • terms_dic : 유효기간 문자 : 개월 수(ex - {'A' : 6} )를 담기 위한 딕셔너리
  • year : 현재 날짜의 year에서 privacies[i]의 year를 뺀 후 12 곱한 값을 저장하기 위한 변수(개월 수)
  • month : 현재 날짜의 month에서 privacies[i]의 month를 뺀 값을 저장하기 위한 변수 
  • day : 현재 날짜의 day에서 privaccies[i]의 day를 뺀 값을 저장하기 위한 변수
  • term : 유효기간에 해당하는 개월 수 * 28(= 몇 일인지)

2. 첫번째 반복문을 통해 유효기간에 해당하는 문자에 개월수를 저장해줌.(ex - {'A' : 6}

3. 두번째 반복문을 통해 현재날짜에서 privacies[i]에 해당하는 날짜를 뺀 일 수를 비교한 후 파기해야하면 answer에 추가

 

 

코드 :

def solution(today, terms, privacies):
    answer = []
    terms_dic = dict()
    for i in range(len(terms)):
        terms_dic[terms[i][0]] = int(terms[i][2:])
        
    for i in range(len(privacies)):
        year = (int(today[:4]) - int(privacies[i][:4]))*12
        month = (int(today[5:7]) - int(privacies[i][5:7]))
        day = int(today[8:10]) - int(privacies[i][8:10])
        term = terms_dic[privacies[i][-1]] * 28
        if (year + month) * 28 + day >= term:
            answer.append(i+1)
    return answer

 

728x90
반응형
Comments