728x90
Q. 약관 종류에 따른 유효기간이 있고 개인정보 수집일자와 약관종류에 따라 파기해야하는지 아닌지
- 2000<= YYYY <= 2022
- 1 <= MM <= 12
- 1 <= DD <= 28
def solution(today, terms, privacies):
answer = []
terms_kv ={}
for term in terms:
terms_kv[term.split(" ")[0]] = term.split(" ")[1]
for pr in range(len(privacies)):
deadline=terms_kv[privacies[pr].split(" ")[1]]
year=int(today.split(".")[0])-int(privacies[pr].split(" ")[0].split(".")[0])
month=int(today.split(".")[1])-int(privacies[pr].split(" ")[0].split(".")[1])
day=int(today.split(".")[2])-int(privacies[pr].split(" ")[0].split(".")[2])
if day<0:
month-=1
day=28+day
if month<0:
year-=1
month=12+month
r=month*28+day+year*12*28
a,b=divmod(r, 28)
if a>=int(deadline): answer.append(pr+1)
return answer
map() 함수를 이용해 깔끔하게 가능하니 참고
def to_days(date):
year, month, day = map(int, date.split("."))
return year * 28 * 12 + month * 28 + day
def solution(today, terms, privacies):
months = {v[0]: int(v[2:]) * 28 for v in terms}
today = to_days(today)
expire = [
i + 1 for i, privacy in enumerate(privacies)
if to_days(privacy[:-2]) + months[privacy[-1]] <= today
]
return expire
728x90
'Python > 프로그래머스' 카테고리의 다른 글
[LV2] 귤 고르기 (1) | 2024.12.04 |
---|---|
[LV1] 신고 결과 받기 - 2022 KAKAO BLIND RECRUITMENT (1) | 2024.11.29 |
[LV1] 데이터 분석 - PCCE 기출문제 (1) | 2024.11.28 |
[LV1] 이웃한 칸 - PCCE 기출문제 (0) | 2024.11.27 |
[LV1] 지폐 접기 - PCCE 기출문제 (2) | 2024.11.26 |