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的更多相关文章

  1. 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, ...

  2. Project Euler 19 Counting Sundays( 蔡勒公式计算星期数 )

    题意:在二十世纪(1901年1月1日到2000年12月31日)中,有多少个月的1号是星期天? 蔡勒公式:计算 ( year , month , day ) 是星期几 以下图片仅供学习! /****** ...

  3. Problem 19

    Problem 19 You are given the following information, but you may prefer to do some research for yours ...

  4. 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 ...

  5. 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目

    [题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  6. HDU-2952 Counting Sheep (DFS)

    Counting Sheep Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  7. hdu Counting Sheepsuanga

    算法:深搜 题意:让你判断一共有几个羊圈: 思路:像四个方向搜索: Problem Description A while ago I had trouble sleeping. I used to ...

  8. UVA - 10574 Counting Rectangles

    Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...

  9. HDU 2952 Counting Sheep(DFS)

    题目链接 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the cei ...

随机推荐

  1. [多线程同步练习]PV操作

    看一个较为复杂的生产者-消费者问题: 问题描述 桌子上有一只盘子,每次只能向其中放入一个水果.爸爸专向盘子中放苹果,妈妈专向盘子中放橘子,儿子专等吃盘子中的橘子,女儿专等吃盘子中的苹果.只有盘子为空时 ...

  2. C语言队列的实现

    队列是常用的数据结构之一,下面给出一个链式队列的实现: 头文件Queue.h #ifndef Queue_H #define Queue_H typedef int Item; typedef str ...

  3. php对xml的处理

    $paymentResult  = $ips='<Ips><GateWayRsp><head><ReferenceID></ReferenceID ...

  4. php的模板引擎

    设计一个交互式的网站,我们需要关注两个主要的问题:分别是图形用户界面和业务逻辑.例如,一个标准的web开发小组由两三个美工和三个程序员组成,则设计流程是:美工设计者制作了项目的网站的界面模板,然后把它 ...

  5. python递归函数下不能正常使用yield

    # -*- coding:utf-8 -*- import os import time file_list = [] def findFile(path): listFile = os.listdi ...

  6. 新手笔记-linux一些命令

    vim ~/.vimrc  写入 set nu    以后使用vim就自动显示行号. shift + v 行选择 x 删除 u 撤销  ctrl + r 反撤销 file test.c  查看文件类型 ...

  7. SQL Server 一些重要视图2

    1. sys.dm_tran_session_transactions 为每一个没有关闭的事务返回一行.session_id 可以与sys.dm_exec_connections.session_id ...

  8. 解密电子书之四:MCU(freescale)

    谈完国产的君正,让我们再看看呛了君正财路的freescale iMX51. 这是freescale近期的主打产品,用的是ARM Cortex A8架构,主频在消费电子领域最高可达800MHz,在工业领 ...

  9. Cortex-M3学习日志(六) -- ADC实验

    上一次简单的总结了一下DAC方面的知识,好吧,这次再来总结一下ADC方面的东东.ADC即Analog-to-Digital Converter的缩写,指模/数转换器或者模拟/数字转换器.现实世界是由模 ...

  10. 文件转换dll mingw

    MinGW:c -> o           gcc -c a.cc -> exe         gcc a.c libs.o -o a.exe (从主程序a.c,附加libs,生成a. ...