1.1.2---Friday the Thirteenth
来源:互联网 发布:美国税收数据 编辑:程序博客网 时间:2024/06/08 00:45
Friday the Thirteenth
Is Friday the 13th really an unusual event?
That is, does the 13th of the month land ona 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 monthlands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturdayover 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 andwill not exceed 400.
Note that the start year is NINETEENHUNDRED, not 1990.
There are few facts you need to know beforeyou can solve this problem:
January 1, 1900 was on a Monday.
Thirty days has September, April, June, andNovember, all the rest have 31 except for February which has 28 except in leapyears when it has 29.
Every year evenly divisible by 4 is a leapyear (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leapyear)
The rule above does not hold for centuryyears. 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 aleap year.
Do not use any built-in date functions inyour 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
13号又是星期五是一个不寻常的日子吗?
13号在星期五比在其他日少吗?为了回答这个问题,写一个程序来计算在n年里13
日落在星期一,星期二......星期日的次数.这个测试从1900年1月1日到
1900+n-1年12月31日.n是一个非负数且不大于400.
这里有一些你要知道的:
1900年1月1日是星期一.
4,6,11和9月有30天.其他月份除了2月有31天.闰年2月有29天,平年2月有28天.
年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年)
以上规则不适合于世纪年.可以被400整除的世纪年为闰年,否则为平年.所以,1700,1800,1900和2100年是平年,而2000年是闰年.
请不要预先算好数据!
PROGRAM NAME: friday
INPUT FORMAT
一个整数n.
SAMPLE INPUT (file friday.in)
20
OUTPUT FORMAT
七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一.....星期五的次数.
SAMPLE OUTPUT (file friday.out)
36 33 34 33 35 35 34
/*
ID: ******
PROG: friday
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
ofstream fout ("friday.out");
ifstream fin ("friday.in");
intn,i,j,k,day;
intst[8];
memset(st,0,sizeof(st));//数组置0
fin>>n;
day=0;
for(i=1900;i<=1900+n-1;i++)
for(j=1;j<=12;j++)
for(k=1;k<=31;k++)
{
day++;
if(k==13)//每月13号
st[day%7]++;
if((j==4||j==6||j==9||j==11)&&k==30)//每月仅30天的月份
break;
if(!((i%4==0&&i%100!=0)||i%400==0)&&j==2&&k==28)//非闰年2月有28天
break;
if(j==2&&k==29)//闰年2月29天
break;
}
fout<<st[6]<<"";
for(i=0;i<=4;i++)
fout<<st[i]<<"";
fout<<st[5]<<endl;
return 0;
}
- 1.1.2---Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth (friday)
- USACO 1.1 Friday the Thirteenth (friday)
- USACO 1.1-Friday the Thirteenth
- 1.1.5 Friday the Thirteenth
- usaco 1.1:Friday the Thirteenth
- 1.1.6.Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- 1.1.3 Friday the Thirteenth
- usaco/1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- Section 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.3 Friday the Thirteenth
- USACO:Section 1.1 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- 输入两个大整数,求和
- p4jmvc 内测版
- sleep()和wait()的区别
- HDOJ 1023 卡特兰数
- 使用Javascript限制文本框只允许输入数字
- 1.1.2---Friday the Thirteenth
- Linux socket的几种地址结构 sockaddr与sockaddr_in,sockaddr_un
- 开源项目之Android StandOut(浮动窗口)
- 求出所有的1/k=1/x+1/y的情况
- 【黑马程序员】二进制图片的读取(学习笔记)
- 只有 IE 的 HTMLDOMNode 有 replaceNode 与 swapNode 方法
- C#调入网页的办法
- setbuf【练习5.1】备注
- The Binding of a Data Member