Notice
Recent Posts
Recent Comments
Link
250x250
반응형
DecordRay
[프로그래머스] Level1 : 개인정보 수집 유효기간[Python] 본문
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
반응형
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Level1 : 둘만의 암호[Python] (0) | 2023.02.06 |
---|---|
[프로그래머스] Level1 : 옹알이(2)[Python] (0) | 2023.02.06 |
[프로그래머스] Level1 : 햄버거 만들기[Python] (0) | 2023.02.03 |
[프로그래머스] Level1 : 문자열 나누기[Python] (0) | 2023.02.03 |
[프로그래머스] Level1 : 기사단의 무기[Python] (0) | 2023.02.03 |