首页 > 其他 > 详细

project euler 19: Counting Sundays

时间:2016-05-04 20:57:41      阅读:156      评论:0      收藏:0      [点我收藏+]
import datetime
count = 0
for y in range(1901,2001):
    for m in range(1,13):
        if datetime.datetime(y,m,1).weekday() == 6:
            count += 1
print count


datetime此功能很好用。省去了计算的麻烦。

count = 0
days = 1
year = 365
normal = [31,28,31,30,31,30,31,31,30,31,30,31]
leap = [31,29,31,30,31,30,31,31,30,31,30,31]
for i in range(1900,2001):
    if i % 4 ==0 and i != 1900:
        year = 366
        temp = leap
    else:
        year = 365
        temp = normal
    for j in range(12):
        if days%7 == 0:
            count += 1
            days += temp[j]
        else:
            days += temp[j]

print(count)

 

project euler 19: Counting Sundays

原文:http://www.cnblogs.com/zhourong1104/p/5459532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!