Problem 19

  1. 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-012000-12-31)?
  1. def leep_year(year):
  2. if year % 100 == 0: # century
  3. if year % 400 == 0:
  4. return True
  5. else:
  6. if year % 4 == 0:
  7. return True
  8. return False
  9.  
  10. week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
  11. month = {'January': 31, 'February': 28, 'March': 31, 'April': 30, 'May': 31, 'June': 30,
  12. 'July': 31, 'August': 31, 'September': 30, 'October': 31, 'November': 30, 'December': 31}
  13.  
  14. count = 0
  15. day = 'Monday' # 1900-01-01是星期一
  16. index = 0
  17. for year in range(1900, 2001):
  18. if leep_year(year): # 闰年
  19. month['February'] = 29
  20. else: # 平年
  21. month['February'] = 28
  22. for m, d in month.items():
  23. if day == 'Sunday':
  24. count += 1
  25. index = week.index(day) + d % 7
  26. if index >= 7:
  27. index %= 7
  28. day = week[index]
  29. if year == 1900: # 如果是1900年,归零(从1901-01-01到2000-12-31)
  30. count = 0
  31. print(count)
  1.  

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. HDU 5294 Tricks Device(多校2015 最大流+最短路啊)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Problem Description Innocent Wu follows Dumb Zha ...

  2. 关于ffmpeg的安装具体步骤和说明

    一.windows安装: 直接下载地址: https://ffmpeg.zeranoe.com/builds/ https://ffmpeg.zeranoe.com/builds/win64/stat ...

  3. IOS6.0自带下拉刷新控件UIRefreshControl

    1.UIRefreshControl必需要在IOS6.0以后才干使用,同一时候他仅仅能在UITableViewController类中才干够使用 2.使用比較简单 self.refreshContro ...

  4. Codeforces--630K--Indivisibility(容斥)

     K - Indivisibility Crawling in process... Crawling failed Time Limit:500MS     Memory Limit:65536 ...

  5. Human Gene Functions(dp)

    http://poj.org/problem?id=1080 #include <stdio.h> #include <stdlib.h> #include <strin ...

  6. Apache 虚拟主机 配置方法

    打开httpd.conf文件 去掉LoadModule vhost_alias_module modules/mod_vhost_alias.so前面的#号 去掉Include conf/extra/ ...

  7. B - Lucky Division

    Problem description Petya loves lucky numbers. Everybody knows that lucky numbers are positive integ ...

  8. 如何正确从windows系统(自己电脑)远程访问Linux系统(他人电脑)的mysql数据库(图文详解)

    这里,需要Linux系统开了root用户,我这给root用户密码为root.     同时,在mysql -uroot -proot执行进去之后 update user setHost='%' whe ...

  9. oracle-3种工具使用

    1:原命令行,dos 2:sqlplus,图形界面 3:isqlplus,网页版的.(假如自己机器无法安装oracle,可通过别人ip地址去使用oracle,http://ip:5560/isqlpl ...

  10. IN、EXISTS的相关子查询用INNER JOIN 代替--性能优化

    如果保证子查询没有重复 ,IN.EXISTS的相关子查询可以用INNER JOIN 代替.比如: IN.EXISTS的相关子查询用INNER JOIN 代替--sql2000性能优化