Problem 19

You are given the following information, but you may prefer to do some research for yourself.
以下信息仅供参考(你可能会想自己去百度):
1 Jan 1900 was a Monday.  1900年一月一号是星期一
Thirty days has September, 九月、四月、六月以及十一月有30天
April, June and November.
All the rest have thirty-one, 其他月份有31天
Saving February alone, 二月份比较特殊
Which has twenty-eight, rain or shine. 闰年29天,平年28天
And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
闰年指可以被4整除的年份,但如果是世纪(如:1900)的话,需要能够整除400才算闰年
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
二十世纪有多少个星期天在月份的第一天(从1901-01-01到2000-12-31)?
def leep_year(year):
if year % 100 == 0: # century
if year % 400 == 0:
return True
else:
if year % 4 == 0:
return True
return False week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
month = {'January': 31, 'February': 28, 'March': 31, 'April': 30, 'May': 31, 'June': 30,
'July': 31, 'August': 31, 'September': 30, 'October': 31, 'November': 30, 'December': 31} count = 0
day = 'Monday' # 1900-01-01是星期一
index = 0
for year in range(1900, 2001):
if leep_year(year): # 闰年
month['February'] = 29
else: # 平年
month['February'] = 28
for m, d in month.items():
if day == 'Sunday':
count += 1
index = week.index(day) + d % 7
if index >= 7:
index %= 7
day = week[index]
if year == 1900: # 如果是1900年,归零(从1901-01-01到2000-12-31)
count = 0
print(count)
												

Problem 19的更多相关文章

  1. (Problem 19)Counting Sundays

    You are given the following information, but you may prefer to do some research for yourself. 1 Jan ...

  2. Common Bugs in C Programming

    There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...

  3. B. Checkout Assistant 01背包变形

    http://codeforces.com/problemset/problem/19/B 对于每个物品,能偷多ti个,那么先让ti + 1, 表示选了这个东西后,其实就是选了ti + 1个了.那么只 ...

  4. The Brain as a Universal Learning Machine

    The Brain as a Universal Learning Machine This article presents an emerging architectural hypothesis ...

  5. 【BFS】Tester Program

    [poj1024]Tester Program Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2760   Accepted ...

  6. softmax实现(程序逐句讲解)

    上一个博客已经讲了softmax理论部分,接下来我们就来做个实验,我们有一些手写字体图片(28*28),训练样本(train-images.idx3-ubyte里面的图像对应train-labels. ...

  7. [NOIP 2014] 寻找道路

    [题目链接] http://uoj.ac/problem/19 [算法] 首先,在反向图上从终点广搜,求出每个点是否可以在答案路径中 然后在正向图中求出源点至终点的最短路,同样可以使用广搜 时间复杂度 ...

  8. Python练习题 046:Project Euler 019:每月1日是星期天

    本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...

  9. 《DSP using MATLAB》Problem 5.19

    代码: function [X1k, X2k] = real2dft(x1, x2, N) %% --------------------------------------------------- ...

随机推荐

  1. Atom编辑器折腾记_(15)JS代码片段补全(插件:javascript-snippets)

    题外话 这款插件就比較重量级了-.用熟悉了写原生JS的效率要提升非常多--并且,不仅支持JS还包括了nodejs snippet javascript-snippets 插件作者: zenorocha ...

  2. 《Java课程实习》日志(周二)

    import java.awt.EventQueue; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.sw ...

  3. 通过loosejar清理应用中冗余的jar包

    随着应用规模的逐渐增大,依赖的jar包数量也大幅添加.当中不乏多余的,用不到的jar包,占用了大量的宝贵空间.通过loosejar这个工具.便可轻松找到"滥竽充数"的jar包了~ ...

  4. 关于PHP会话:session和cookie

    会话处理解决什么问题 HTTP(超文本传输协议)定义了通过万维网(WWW)传输文本.图形.视频和全部其它的数据的规则.HTTP是一种无状态协议,每次请求的处理,都与之前和之后的请求无关. 会话处理是这 ...

  5. 1+2+3+...+n不能用while、for、if else等实现

    问题描写叙述 求 1+2+ - +n ,要求不能使用乘除法. for . while . if . else . switch . case 等keyword以及条件推断语句. 实际意义不大,题目涉及 ...

  6. 利用jquery将页面中所有目标为“#‘的链接改为其他URL

    有一张页面草稿,开始时为了方便,里面差不多所有的<a>都指向了"#".现在要修改为另一个地址,难道要全部修改吗?用jquery 改改就好.代码如下: <scrip ...

  7. HDU 5533/ 2015长春区域 G.Dancing Stars on Me 暴力

    Dancing Stars on Me Problem Description The sky was brushed clean by the wind and the stars were col ...

  8. hdoj--3790--最短路径问题(双权值迪杰斯特拉)

     最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. B1786 [Ahoi2008]Pair 配对 逆序对+dp

    这个题有点意思,一开始没想到用dp,没啥思路,后来看题解才恍然大悟:k才1~100,直接枚举每个-1点的k取值进行dp就行了.先预处理出来sz[i][j]  i左边的比j大的数,lz[i][j]  i ...

  10. springMVC返回数据的四种方式

    转自:https://blog.csdn.net/itcats_cn/article/details/82119673 springMVC返回数据的四种方式:第一种,通过request.setAttr ...