(Problem 19)Counting Sundays
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)?
#include <stdio.h>
#include <stdbool.h> const int a[][] = {{,,,,,,,,,,,},
{,,,,,,,,,,,}}; bool leapYear(int n) //判断闰年
{
return (((n % ==) && (n % !=)) || (n % == ));
} bool issunday(int n) //判断某天是否是星期天
{
return (n % == ? true : false);
} void solve(void)
{
int num, i, j, count;
count = ; i = ;
num = ;
while(i < ) { int t = (leapYear(i) ? : ); //判断闰年
for(j = ; j < ; j++) {
num += a[t][j];
if(issunday(num)) count++;
}
i++;
}
printf("%d\n",count);
} int main(void)
{
solve();
return ;
}
|
Answer:
|
171 |
(Problem 19)Counting Sundays的更多相关文章
- project euler 19: Counting Sundays
import datetime count = 0 for y in range(1901,2001): for m in range(1,13): if datetime.datetime(y,m, ...
- Project Euler 19 Counting Sundays( 蔡勒公式计算星期数 )
题意:在二十世纪(1901年1月1日到2000年12月31日)中,有多少个月的1号是星期天? 蔡勒公式:计算 ( year , month , day ) 是星期几 以下图片仅供学习! /****** ...
- Problem 19
Problem 19 You are given the following information, but you may prefer to do some research for yours ...
- Project Euler:Problem 76 Counting summations
It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...
- 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目
[题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- HDU-2952 Counting Sheep (DFS)
Counting Sheep Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- hdu Counting Sheepsuanga
算法:深搜 题意:让你判断一共有几个羊圈: 思路:像四个方向搜索: Problem Description A while ago I had trouble sleeping. I used to ...
- UVA - 10574 Counting Rectangles
Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...
- HDU 2952 Counting Sheep(DFS)
题目链接 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the cei ...
随机推荐
- Git操作流水账
一.关于Git Git是一个分布式版本控制/软件配置管理软件,原是Linux内核开发者林纳斯·托瓦兹(Linus Torvalds)为更好地管理Linux内核开发而设计. 二.Git的环境配置 2.1 ...
- 6.828 lab1 bootload
MIT6.828 lab1地址:http://pdos.csail.mit.edu/6.828/2014/labs/lab1/ 第一个练习,主要是让我们熟悉汇编,嗯,没什么好说的. Part 1: P ...
- mysql 存储过程中的declare 和 set @的两种变量的区别
两者在手册中的说明: DECLARE var_name[,...] type [DEFAULT value]这个语句被用来声明局部变量.要给变量提供一个默认值,请包含一个DEFAULT子句.值可以被指 ...
- 用CSS3绘制图形
参考资料:http://blog.csdn.net/fense_520/article/details/37892507 本文非转载,为个人原创,转载请先联系博主,谢谢~ 准备: <!DOCTY ...
- 织梦list文章列表按权重排序
织梦的文章列表按权重排序 DEDECMS(织梦)5.6系统支持文档权重weight排序,可以在模板中使用: {dede:arclist row='10' titlelen='50' orderby=' ...
- 如何查询Oracle性能监控
1.监控等待事件select event,sum(decode(wait_time,0,0,1)) prev, sum(decode(wait_time,0,1,0)) curr,count(*)fr ...
- Oracle EBS-SQL (SYS-23):用户权限查询.sql
select b.user_name, b.description, b.creation_date, d.responsibility_name from fnd_user b, fnd_use ...
- java.util.Timer分析源码了解原理
Timer中最主要由三个部分组成: 任务 TimerTask . 任务队列: TaskQueue queue 和 任务调试者:TimerThread thread 他们之间的关系可以通过下面图示: ...
- 利用指针突破C++编译器的防线
C++ 面向对象的一大特性就是封装,使用不同的访问控制符来控制外接对其的访问权限.比如: class A { public: A(): i(){} void print(){ cout << ...
- Twitter模块开发
Twitter模块开发 关于Twitter这一块,自发这篇博文之后有很多人问我,有的验证成功了不跳转,或者其它原因什么的 =======我看了一下,这篇博文里面有写呀,下面以红色粗体文字注明一下 Tw ...