# hihocoder:#1148 : 2月29日

1. 年份能被4整除但不能被100整除

2. 年份能被400整除

### 数据范围

1 ≤ T ≤ 550

2000 ≤ year ≤ 3000

2000 ≤ year ≤ 2×109

4
January 12, 2012
March 19, 2012
August 12, 2899
August 12, 2901
August 12, 2000
August 12, 2005
February 29, 2004
February 29, 2012

Case #1: 1
Case #2: 0
Case #3: 1


Case #4: 3

#-*-coding:utf-8-*-

import copy

def judge_before(temp_day1,temp_day2,month,days):

if(temp_day1[2] < temp_day2[2]):
return True
else:
if(temp_day1[2] == temp_day2[2]):
if(month.index(temp_day1[0]) < month.index(temp_day2[0])):
return True
else:
if(month.index(temp_day1[0]) == month.index(temp_day2[0])):
if(int(temp_day1[1]) <= temp_day2[1]):
return True
else:
return False
else:
return False
else:
return False

#year1_list after year2_list
def judge_after(year1_list,year2_list,month,days):
if(year1_list[2]>year2_list[2]):
return True
else:
if(year1_list[2]==year2_list[2]):
if(month.index(year1_list[0])>month.index(year2_list[0])):
return True
else:
if(month.index(year1_list[0])==month.index(year2_list[0])):
if(int(year1_list[1])>int(year2_list[1])):
return True
else:
return False
else:
return False
else:
return False

return

def count_leapyear(year1_list,year2_list,month,days):

count = 0

year_start = year1_list[2]
year_end = year2_list[2]
year_judge = []
year_judge.append('February')
year_judge.append('29')

if((year_start == year_end) and((year_start %4 == 0 and year_start%100 != 0) or (year_start %400 ==0))):
year_judge.append(year_start)
if(judge_before(year1_list, year_judge, month, days)):
count = 1
return count
else:
return 0

for i in range(year_start+1,year_end):
if((i%4 == 0 and i%100 != 0) or (i%400 == 0)):
count += 1

if((year_start %4 == 0 and year_start%100 != 0) or (year_start %400 ==0)):
year_judge.append(year1_list[2])

if (judge_before(year1_list, year_judge, month, days)):
count += 1

if((year_end %4 == 0 and year_end%100 != 0) or (year_end %400 ==0)):
if(len(year_judge)==3):
year_judge.pop()
year_judge.append(year2_list[2])
else:
year_judge.append(year2_list[2])

if(judge_after(year2_list, year_judge, month, days)):
count += 1

return count

def legal_year(year_list,month,days,big_year):
if(year_list[2]>=2000 and year_list[2]<=big_year):
if((year_list[2]%4 == 0 and year_list[2]%100!=0)or(year_list[2]%400==0)):
if(year_list[0]=='February'):
if(int(year_list[1])<=29):
return True
else:
return False
else:
if(year_list[0] not in month):
return False
else:
if(int(year_list[1])<=days[month.index(year_list[0])]):
return True
else:
return False
else:
if(year_list[0] not in month):
return False
else:
if(int(year_list[1])<=days[month.index(year_list[0])]):
return True
else:
return False

else:
return False

def split_day(year1,year2):

year1_list = []
year2_list = []
temp_list = []

temp_list = copy.deepcopy(year1.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']
days = [31,28,31,30,31,30,31,31,30,31,30,31]

num = int(raw_input())

if(num>=1 and num<=550):

for i in range(num):
year1 = raw_input()
year2 = raw_input()

year1_list,year2_list = split_day(year1, year2)

if((legal_year(year1_list, month, days, 3000))and (legal_year(year2_list, month, days, 2000000000))):
if (judge_before(year1_list, year2_list,month,days)):
print 'Case #%i: %i' % (i+1,count_leapyear(year1_list, year2_list, month, days))
else:
break
else:
break



#### hihocoder #1148 : 2月29日（容斥原理，有坑）

2018-04-07 20:25:28

#### hiho1148 编程之美

2016-05-17 21:51:15

#### 1148: 组合三位数之一

2017-07-08 12:08:04

#### hihocoder #1082然而沼跃鱼早就看穿了一切

2016-08-26 11:02:35

#### hihoCoder题库1051补提交f卡

2016-04-04 17:48:50

#### hihocoder:#1148 : 2月29日,python版本

2016-09-01 10:16:57

#### ZOJ 1148

2012-08-23 23:20:53

#### Sicily 1148 过河

2016-03-12 18:22:54

#### hihoCoder 题目答案

2017-10-04 16:10:23

#### 统计起始日期之间有多少个2月29日

2015-04-19 23:50:12