You are given the following information, but you may prefer to do some research for yourself.
• 1 Jan 1900 was Monday.
• Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
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.

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

public class Test {

public static void main(String args[]) {
int count = 0;
int week = 1;
for (int i = 1900; i <= 2000; i++) {
for (int j = 1; j <= 12; j++) {
week = (week + getMoDay(i, j)) % 7;
if (week == 0 && i >= 1901)
count++;
}
}
System.out.println(count);
}

public static int getMoDay(int year, int month) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
return 31;
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}
if (month == 2) {
if (year % 100 == 0) {
if (year % 400 == 0)
return 29;
else
return 28;

} else {
if (year % 4 == 0)
return 29;
else
return 28;
}
}
return 0;
}
}

You are given the following information, but you may prefer to do some research for yourself.
• 1 Jan 1900 was Monday.
• Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
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.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

How many Sundays fell on the first of the month during the twentieth century相关推荐

  1. Project Euler 题解 #19 Counting Sundays

    题目:Counting Sundays You are given the following information, but you may prefer to do some research ...

  2. Problem 19:Counting Sundays

    原题链接:http://projecteuler.net/problem=19 You are given the following information, but you may prefer ...

  3. Project Euler in Java [001-040]

    目录:英语原题见代码注释 001_三或五的倍数 002_偶斐波那契数 003_最大质因数 004_最大乘积回文数 005_最小公倍数 006_"和的平方"与"平方的和&q ...

  4. MID-TERM EXAMINATION 1

    MID-TERM EXAMINATION 1 Listening Comprehension Section A 0次播放机会 A) A Father's Day card. B) A Father' ...

  5. 新概念英语第四册16-30课(转)

    Lesson 16  The modern city 现代城市 1.  在工业生活的组织里In the organization of industrial life 这种影响the influenc ...

  6. New 900 Sentences

    Greetings 问候语 1. Hello. 你好! 2. Good morning. 早上好. 3. I am Kate Green. 我是凯特·格林. 4. Are you Tom Brown? ...

  7. C语言中excit函数,2010年12月英语四级全真预测试卷及答案解析(4)

    2010年12月英语四级全真预测试卷及答案解析(4) 来源:网络发布时间:2010-12-06 下面是英语四级考试全真预测试卷,育路教育网特别为您搜集整理: 2010年12月大学英语四级考试全真预测试 ...

  8. 《高效的项目和团队》

    Productive Projects and Teams是一本好书. 许多其中许多关于管理和沟通的精辟言论让我大有相见很晚之感.其实不仅是软件的开发项目,任何项目,甚至任何行业的管理,都首先是对人的 ...

  9. 明翰英语教学系列之雅思阅读篇V0.9(持续更新)

    文章目录 传送门 6. 阅读 READING 6.1 阅读评分标准 6.2 阅读题型 `6.2.1 阅读填空题` `摘要填空题(Summary)` `无选项摘要填空` 1. 找定位词 2. 确定答案词 ...

最新文章

  1. 计算机二级c语言考完多久出成绩,计算机二级C语言的成绩什么时候出来?
  2. 5G NGC — 关键技术 — 网络切片 — 概述
  3. 图像对象paip.Image对象出现“对象当前正在其他地方使用或者GDI+中发生一般性错误的解决...
  4. 通过 .htaccess 实现缓存策略
  5. 自制简易AP柱面定向天线(zz)
  6. 判断一个程序员水平高低的标准?
  7. php数据趋势曲线,数据曲线图怎么做
  8. java 分批同时处理_java中List集合分批处理
  9. oracle asm ora 15041,ORA-15041,ORA-01274 故障解决实例
  10. Android TabHost和xml定义Menu应用
  11. 【劲峰论道时空分析技术-学习笔记】2 时空可视化
  12. C++实现获取汉字拼音首字母
  13. 霍尼韦尔:物联网“起跑线”上的巨头转型之路
  14. Python安装和环境配置
  15. ABP文档 - 通知系统
  16. Android多国语言的国家代码
  17. 三网融合融什么融,团购网站团什么团【涂雅速涂】
  18. 京东淘宝拼多多自动查券找券搜券返利机器人实现方法分享
  19. FileWriter学习
  20. 20220211纪中集训总结

热门文章

  1. 基于C语言的学生信息管理系统_(更新版)_(附源码和安装包)_课程设计_☆*往事随風*☆的博客
  2. http状态码查询 http_code状态码大全《详细》
  3. 计算机机房ups电池常用配置表,机房UPS电池容量、后备电池配置、使用时间快速计算方法!...
  4. python定时爬虫三种方法
  5. 【转】PHP之Trait详解 以及 trait 冲突的解决 insteadof
  6. SQL中limit用法
  7. seata clientID 及channel选择
  8. 过招多家大厂提炼的iOS面试心经
  9. 查看MySQL每个表占用的空间
  10. mysql查看数据库表空间占用情况