The number of leap years to a certain year is actually very simple. Set the year to be calculated as a, and the number of leap years up to a year (including year a) is:
leap years =int (A/4)-int (a/100) +int (a/400)
Here: int is taken as Integer function
#-*-coding:utf-8-*-' @author: liuhuiting date:2016 year August 31 Description: The number of leap years to a certain year is actually very simple. Set the year to be calculated as a, The number of leap years up to a year (including year a) is: number of leap years =int (A/4)-int (a/100) +int (a/400) here: INT for take integer function ' import copy def is_leapyear ': Return (y
Ear%4==0 and Year%100!=0) or (year%400==0) def calculate_year (year,mon,day): sum = YEAR/4-year/100 + year/400 if (is_leapyear) and (Mon<2 or (mon==2 and int (day) <29)): Sum-= 1 return sum def split_da Y (year1,year2): Year1_list = [] Year2_list = [] Temp_list = [] temp_list = Copy.deepcopy (ye
Ar1.split (', ')) temp = Temp_list[0].split () temp.append (int (temp_list[1)) year1_list = copy.deepcopy (temp)
Temp_list = Copy.deepcopy (Year2.split (', ')) temp = Temp_list[0].split () temp.append (int (temp_list[1)) Year2_list = copy.deepcopy (temp) return year1_list,year2_list if __name__ = = ' __main__ ': month = [' January ' , ' February ', ' March ', ' April ', ' may ', ' June ', ' JUly ', ' August ', ' September ', ' October ', ' November ', ' December '] res = 0 num = Int (raw_input ()) for I in range
(num): year1 = Raw_input () year2 = Raw_input () year1_list,year2_list = Split_day (year1, YEAR2) For j in Range (): if (Year1_list[0]==month[j]): Mon1 = j+1 if (year2
_LIST[0]==MONTH[J]): Mon2 = j+1 num1 = calculate_year (year1_list[2), Mon1, year1_list[1]) num2 = Calculate_year (year2_list[2], Mon2, year2_list[1]) res = NUM2-NUM1 if (is_leapyear (year1_list[2)
) and mon1==2 and Int (year1_list[1]) ==29): res = 1 print ' Case #%d:%d '% (i+1,res)