标签:python
You are given the following information, but you may prefer to do some research for yourself.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)
翻译:
现提供你如下信息,不过你可能希望自己印证一下。
请问,在20世纪中(从1901年1月1日到2000年12月31日)总共有多少个月份的第一日是星期天?
def f(year,month): tmpDay=1 if month == 1 or month == 2: month += 12 year-=1 if ((year<1752) or (year==1752 and month<9) or (year==1752 and month==9 and tmpDay<3)): a = (tmpDay + 2*month + 3*(month+1)/5 + year + year/4 +5) % 7; else: a = (tmpDay + 2*month + 3*(month+1)/5 + year + year/4 - year/100 + year/400)%7 return a resu=0 for i in range(1901,2001): for j in range(1,13): if f(i,j)==1 : resu+=1 print resu
projecteuler---->problem=19----Counting Sundays,布布扣,bubuko.com
projecteuler---->problem=19----Counting Sundays
标签:python
原文地址:http://blog.csdn.net/china_zoujinyong/article/details/28586467