문제
링크텍스트
풀이
def solution(date1, date2):
class calendar:
def __init__(self,date):
self.months = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
self.year = date[0]
self.month = date[1]
self.day = date[2]
self.days_00010101 = self.f_ymd(date)
def f_ymd(self,date):
year = date[0]
month = date[1]
day = date[2]
def f_isLeapYear(year):
return 1 if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0) else 0
def f_totalday(year, month, day):
sum = 0
for i in range(year-1):
sum += (365 + f_isLeapYear(i))
for i in range(month-1):
sum += self.months[i]
if month > 2:
sum += f_isLeapYear(year)
sum += day
return sum
return f_totalday(year, month, day)
class calendars:
def __init__(self,dates):
self.n = len(dates)
self.i_cals = []
for i in range(self.n):
self.i_cals.append(calendar(dates[i]))
def f_diff(self,d1,d2):
days1 = d1.days_00010101
days2 = d2.days_00010101
return days2 - days1
def f_add(self,d1,days):
days1 = d1.days_00010101
days2 = days1 + days
i_y = days // 365
i_m = (dyas - iy*365) // 30
i_d = dyas - iy*365 - im*30
year = days1.year + i_y
month = days1.month + i_m
day = days1.day + i_d
if day > 30:
month += 1
day -= 30
if month > 12:
yeay += 1
month -= 12
d2 = calendar([year,month,day])
dd = date2 - d2.days_00010101
for i in range(60):
if dd == 0:
break
i_m = dd > d2.months[d2.months-1]
i_d = dd - i_m*d2.months[d2.months-1]
d2 = calendar([year,month+i_m,day+i_d])
dd = date2 - d2.days_00010101
return d2
i_cals = calendars([date1,date2])
d_d = i_cals.f_diff(i_cals.i_cals[0],i_cals.i_cals[1])
if d_d > 0:
return 1
elif d_d <= 0:
return 0
결과