반응형
def timestamp_create(year, month, day):
timestamp_today = (int(year) * 12 * 28) + (int(month) * 28) + (int(day))
return timestamp_today
def solution(today, terms, privacies):
# timestamp로 비교
year, month, day = today.split('.')
timestamp_today = timestamp_create(year, month, day)
terms_obj = { data.split(' ')[0] : data.split(' ')[1] for data in terms }
answer = []
for idx, data in enumerate(privacies):
p_date, p_type = data.split(' ')
p_year, p_month, p_day = p_date.split('.')
timestamp_p = timestamp_create(p_year, p_month, p_day) + (int(terms_obj[p_type]) * 28)
if int(timestamp_p) <= int(timestamp_today):
answer.append(idx+1)
return answer
def solution(today, terms, privacies):
answer = []
for data in terms:
type, month = data.split(' ')
for idx, val in enumerate(privacies):
date, term_type = val.split(' ')
if term_type == type:
now_year, now_month, now_day = today.split('.')
terms_year, terms_month, terms_day = date.split('.')
if int(terms_month) + int(month) > 12:
year_remainder = (int(terms_month) + int(month)) % 12
if year_remainder == 0:
add_year = ((int(terms_month) + int(month)) // 12) - 1
add_month = 12
else:
add_year = ((int(terms_month) + int(month)) // 12)
add_month = (int(terms_month) + int(month)) % 12
terms_year = int(terms_year) + int(add_year)
if int(terms_month) == 1 and int(terms_day) == 1:
terms_year = int(terms_year) - 1
terms_month = 12
terms_day = 28
else:
if int(terms_day) == 1:
terms_month = add_month - 1
terms_day = 28
else:
terms_month = add_month
terms_day = int(terms_day) - 1
else:
terms_month = int(terms_month) + int(month)
if int(terms_month) == 1 and int(terms_day) == 1:
terms_year = int(terms_year) - 1
terms_month = 12
terms_day = 28
else:
if int(terms_day) == 1:
terms_month = terms_month - 1
terms_day = 28
else:
terms_day = int(terms_day) - 1
if int(terms_year) < int(now_year):
answer.append(idx+1)
elif int(terms_year) == int(now_year):
if int(terms_month) < int(now_month):
answer.append(idx+1)
elif int(terms_month) == int(now_month):
if int(terms_day) < int(now_day):
answer.append(idx+1)
elif int(terms_day) == int(now_day):
pass
else:
pass
else:
pass
else:
pass
answer.sort()
return answer반응형
'삽집하는 개발들 > 알고리즘' 카테고리의 다른 글
| [11일차][프로그래머스][2022 카카오 - 118666]성격유형 검사하기 (0) | 2023.06.21 |
|---|---|
| [10일차][프로그래머스][161990]바탕화면 정리 (0) | 2023.06.20 |
| [8일차][프로그래머스][178871]달리기 경주 (0) | 2023.06.16 |
| [7일차][프로그래머스][172928]공원산책 (0) | 2023.06.14 |
| [6일차] [프로그래머스] [2022 카카오 - 92334]신고 결과 받기 (0) | 2023.06.12 |