728x90
Programmers
개인정보 수집 유효기간
https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제
코드
- privacies 리스트에서 날짜와 약관 유형을 분리해 date, tp 리스트에 저장
- date 리스트의 각 날짜에서 split을 사용해 '.'을 제거
- terms 리스트를 terms_dict 딕셔너리로 변환해 각 약관 유형과 기간을 저장
- 각 privacies 항목에 대해 약관 유형의 기간을 더한 새로운 날짜를 계산. 새로운 날짜가 오늘 날짜보다 작거나 같으면 인덱스를 answer에 추가
- fstring을 사용해 문자열 생성. :04d는 4자리 10진수, 02d는 2자리 10진수
def solution(today, terms, privacies):
answer = []
date, tp = [], []
for i in privacies:
a, b = i.split(' ')
date.append(a)
tp.append(b)
for i in range(len(date)):
date[i] = date[i].replace('.', '')
terms_dict = {}
for i in terms:
term_type, duration = i.split(' ')
terms_dict[term_type] = int(duration)
for i in range(len(date)):
term_type = tp[i]
if term_type in terms_dict:
now = date[i]
new_month = int(now[4:6]) + terms_dict[term_type]
new_year = int(now[:4])
while new_month > 12:
new_year += 1
new_month -= 12
new_date = f"{new_year:04d}{new_month:02d}{now[6:]}"
if new_date <= today.replace('.', ''):
answer.append(i + 1)
return answer
728x90
반응형
'Algorithm' 카테고리의 다른 글
[개념] 해시(Hash) (0) | 2024.06.19 |
---|---|
[프로그래머스] 신고 결과 받기 - 파이썬 (0) | 2024.05.22 |
[프로그래머스] 신규 아이디 추천 - 파이썬 (0) | 2024.05.20 |
[프로그래머스] [PCCE 기출문제] 10번 데이터 분석 - 파이썬 (0) | 2024.05.18 |
[프로그래머스] 성격 유형 검사하기 - 파이썬 (0) | 2024.05.17 |