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. iOS判断并使用百度地图 高德地图 导航 (使用URI,不集成sdk)

    [objc] view plaincopy  1. BOOL hasBaiduMap = NO;   2.         BOOL hasGaodeMap = NO;   3.            ...

  2. 2016-09-06 J2EE基础知识之不知

    1.中间件.容器.Web服务器 1.1中间件 中间件是提供系统软件和应用软件之间连接的软件,以便于软件各部件之间的沟通.中间件处于操作系统和更高一级应用程序之间. J2EE提出的背景: 1)企业级应用 ...

  3. juce 中的ReferenceCountedObjectPtr

    提供了对引用计数对象的管理,其实也就是操作引用计数对象,当引用计数为零的时候将对象销毁,值得学习的是juce是如果将引用计数对象和它的智能指针结合在一起的,这个后面再加分析 //=========== ...

  4. 事件绑定之.bind()

    .bind(eventType[,eventData],handler(eventObject)) 描述:为一个元素绑定一个事件处理程序,bind()绑定方法的时候元素必须已经存在. -eventTy ...

  5. 利用jQuery接受和处理xml数据

    使用jQuery+Servlet接受和处理xml数据,模拟判断用户名是否存在,效果如下: 服务器端 package com.ljq.test; import javax.servlet.http.Ht ...

  6. nginx-configure执行大致流程

    1,configure 命令行参数处理 2,初始化各种文件路径 3,分析源码结构 4,生成编译过程中所需路径 5,准备 .h,.err等编译所需文件 6,写入命令行参数 7,检测环境(系统,编译器,第 ...

  7. AlertDialog基本用法详解

    AlertDialog简单介绍: AlertDialog可以在当前活动界面弹出一个对话框,用于提示一些重要信息或是警告内容. AlertDialog置于所有页面元素之上,能够屏蔽其他控件的交互. 由于 ...

  8. 汇编写下strcpy

    #include <stdio.h> int main() { char *source = "hello world\n"; ] = {}; char *p = de ...

  9. 基于Socket的UDP和TCP编程介绍

    一.概述 TCP(传输控制协议)和UDP(用户数据报协议是网络体系结构TCP/IP模型中传输层一层中的两个不同的通信协议. TCP:传输控制协议,一种面向连接的协议,给用户进程提供可靠的全双工的字节流 ...

  10. [LeetCode][Python]Integer to Roman

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...