USACO 1.1.3 Friday the Thirteenth
来源:互联网 发布:集思宝怎么导出数据 编辑:程序博客网 时间:2024/05/17 14:17
Is Friday the 13th really an unusual event?
That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is positive and will not exceed 400.
Note that the start year is NINETEEN HUNDRED, not 1990.
There are few facts you need to know before you can solve this problem:
- January 1, 1900 was on a Monday.
- Thirty days has September, April, June, and November, all the rest have 31 except for February which has 28 except in leap years when it has 29.
- Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year)
- The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year.
Do not use any built-in date functions in your computer language.
Don't just precompute the answers, either, please.
PROGRAM NAME: friday
INPUT FORMAT
One line with the integer N.SAMPLE INPUT (file friday.in)
20
OUTPUT FORMAT
Seven space separated integers on one line. These integers represent the number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, ..., Friday.SAMPLE OUTPUT (file friday.out)
36 33 34 33 35 35 34
一开始闰年判断错了,结果各种调不出啊。
/*ID: xinming2PROG: fridayLANG: C++*/#include <cstdio>#include <cmath>#include <algorithm>#include <iostream>#include <cstring>#include <map>#include <string>using namespace std;int day[7];int leapyear[13] = {0 , 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};int notleapyear[13] = {0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};int leap(int n){ if(n % 400 == 0)return 1; if(n % 4 == 0) { if(n % 100) { return 1; } } return 0;}int main(){ freopen("friday.in","r",stdin); freopen("friday.out","w" , stdout); int n; while(scanf("%d",&n)!=EOF) { memset(day , 0 , sizeof(day)); int manyday = 1; int now; for(int i = 1900 ; i < n + 1900 ; i++) { if(leap(i)) { for(int j = 1 ; j <= 12 ; j++) { now = manyday + 11; day[now % 7] ++; manyday += leapyear[j]; //cout << ' '<< now % 7 << endl; } //cout << i << endl; } else { for(int j = 1 ; j <= 12 ; j++) { now = manyday + 11 ; day[now % 7] ++; manyday += notleapyear[j]; //cout << i <<'*' << j <<'*'<< manyday << '*'<< now << endl; } } } printf("%d %d %d %d %d %d %d\n",day[5],day[6],day[0],day[1],day[2],day[3],day[4]); } return 0;}/**/
- USACO 1.1.3 Friday the Thirteenth (friday)
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- [USACO 1.1.3] Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO Section 1.1.3 Friday the Thirteenth
- USACO 1.1.3 - Friday the Thirteenth(模拟)
- USACO 1.1-Friday the Thirteenth
- usaco 1.1:Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- usaco/1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1-Friday the Thirteenth
- [原]jquery第一行代码有意思的两点
- Heritrix源码分析(五) 如何让Heritrix在Ecplise等IDE下编程启动
- Heritrix源码分析(六) Heritrix的文件结构分析
- 最大子段和——解题报告
- Heritrix源码分析(七) Heritrix总体介绍
- USACO 1.1.3 Friday the Thirteenth
- 电子商务概述
- 字符串转整形
- Heritrix源码分析(八) Heritrix8个处理器(Processor)介绍
- 2.1.3---Sorting a Three-Valued Sequence
- JDBC中MySQL注册驱动的三种方式
- 字符串轮换
- Design Pattern_Abstract Factory(抽象工厂)
- Heritrix源码分析(九) Heritrix的二次抓取以及如何让Heritrix抓取你不想抓取的URL