You are given the following information, but you may prefer to do some research for yourself.
- 1 Jan 1900 was a 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)?
题目大意:
- 1900年1月1日是星期一。
- 30天的月份有:9月,4月,6月,11月。
- 此外的月份都是31天,当然2月除外。
- 2月在闰年有29天,其他时候有28天。
- 年份可以被4整除的时候是闰年,但是不能被400整除的世纪年(100的整数倍年)除外。
20世纪(1901年1月1日到2000年12月31日)一共有多少个星期日落在了当月的第一天?
#include <stdio.h> #include <stdbool.h> const int a[2][12] = {{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31}}; bool leapYear(int n) //判断闰年 { return (((n % 4 ==0) && (n % 100 !=0)) || (n % 400 == 0)); } bool issunday(int n) //判断某天是否是星期天 { return (n % 7 == 0 ? true : false); } void solve(void) { int num, i, j, count; count = 0; i = 1901; num = 1; while(i < 2000) { int t = (leapYear(i) ? 1 : 0); //判断闰年 for(j = 0; j < 12; j++) { num += a[t][j]; if(issunday(num)) count++; } i++; } printf("%d\n",count); } int main(void) { solve(); return 0; }
Answer:
|
171 |
Completed on Mon, 18 Nov 2013, 03:38
相关推荐
Give "1 Jan 1900 was a Monday", get "How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
To reflect that, and to make the Counting Practices Manual (CPM) even more attractive as a reference manual, the Counting Practices Committee (CPC) decided to restructure CPM 4.2 into four parts: ...
The Function Point Counting Practices Manual is the definitive description of the Function Pointing Counting Standard. Several versions of the manual are available, each describing the standard or ...
Function Point Counting Practices Manual (功能点计算实践手册)4.3版
3D人员计数例程系统文档
The Pleasures of Counting 1996 © Cambridge University Press 1996
These practices are a compilation of acceptable proce- dures for cycle-counting methods employed in fatigue analysis. This standard does not intend to recommend a particular method.
1004. Counting Leaves (30) 来自:http://blog.csdn.net/sunbaigui/article/details/8657008
Source code for the problem The Counting PROBLEM
Function Point Counting Practices Manual 4.1.1 版本。 来自IFPUG,权威资料 The primary objectives of the IFPUG Counting Practices Manual, Release 4.1, are to • Provide a clear and detailed description...
Counting源代码统计器,对开发的代码进行统计,辅助开发者进行开发,也可以用于软件测试时对代码的统计
97D50 problem solving mathematical proofs mathematical problem solving mathematical exploration problem solving strategies mathematics extremal principle invariance principle pigeonhole principle ...
可以统计source有效行,空行,注释行,文件的大小,统计的文件数目的工具
论文Attentional Neural Fields for Crowd Counting,侵删
To reflect that, and to make the Counting Practices Manual (CPM) even more attractive as a reference manual, the Counting Practices Committee (CPC) decided to restructure CPM 4.2 into four parts: ...
输出一段字串中的字符数——程序很小,第一次上传,大家多支持!
Zhang_Cross-Scene_Crowd_Counting_2015_CVPR_paper.pdf
统计代码量的工具 软件开发必备 简单易操作
一个统计代码行的很简单很适用的小工具-a statistical line of code is very simple and very applicable to the small tools
利用差分盒计数法计算图像分维数,利用matlab语言编写