USACO SECTION 1.1 Friday the Thirteenth

 

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: conicoc1
LANG: C
TASK: friday
*/

#include<stdio.h>


int main()
{
	FILE *fin,*fout;
	fin=fopen("friday.in","r");
	fout=fopen("friday.out","w");
	
	int Day[2][12]={
		{
			31,28,31,30,31,30,31,31,30,31,30,31
		}
		,
		{
			31,29,31,30,31,30,31,31,30,31,30,31
		}
	};
	
	int DayCount[7]={
		0,0,0,0,0,0,0
	};
	
	int N,NowYear,NowDay;
	int i,j;
	fscanf(fin,"%d",&N);
	
	NowDay=13%7;
	for(NowYear=1900;NowYear<=1900+N-1;NowYear++)
	{
		j=( (NowYear%4==0 &&NowYear%100!=0) || NowYear%400==0);	
		for(i=0;i<12;i++)
		{
			printf("%d\n",NowDay%7);
			DayCount[NowDay]++;
			NowDay=(NowDay+Day[j][i])%7;	
		}
	} 
	
	fprintf(fout,"%d %d %d %d %d %d %d\n",
	DayCount[6],DayCount[0],DayCount[1],DayCount[2],DayCount[3],DayCount[4],DayCount[5]);
		
	return 0;
}


告诉你1900年的1月1日是星期一

计算到1900+N-1的12月31日时各星期X,正好是13日的次数

 

先打表平年和闰年每月的天数,然后逐月模拟

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值