def solution(today, terms, privacies):
ans = []
i = 0
today = list(map(int,today.split(".")))
termsArr = []
for t in terms:
a,b = t.split(" ")
termsArr.append([a,int(b)])
for p in privacies:
i+=1
date, type = p.split(" ")
date = list(map(int,date.split(".")))
for t in termsArr:
if(type==t[0]):
date[1]+=t[1]
if(date[1]>12):
n = date[1]
if(n%12==0):
date[1]=12
date[0]+=n//12-1
else:
date[1]=n%12
date[0]+=n//12
if(today[0]>date[0]):
ans.append(i)
elif(today[0]==date[0] and today[1]>date[1]):
ans.append(i)
elif(today[0]==date[0] and today[1]==date[1] and today[2]>=date[2]):
ans.append(i)
print(date[0], date[1], date[2])
return ans
다른 사람 풀이
def to_days(date):
y,m,d = map(int,date.split("."))
return y*12*28+m*28+d
def solution(today, terms, privacies):
terms = {t[0]: int(t[2:])*28 for t in terms}
ans = [ i+1 for i, p in enumerate(privacies)
if to_days(p[:-2])+terms[p[-1]] <= to_days(today)]
return ans
나보다 훨씬 깔끔한 풀이. yyyy.mm.dd 형태를 유지한 나와 달리 이 사람은 다 day 수로 변환하는 함수를 만들었다. 문제에서 모든 달은 28일까지 있다고 설정해주었기 때문에 쉽게 바꿀 수 있다.