Friday the Thirteenth黑色星期五
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:jie19952
PROG:friday
LANG:PASCAL
}
const
day:array[1..12]of longint=(31,28,31,30,31,30,31,31,30,31,30,31);
var
n:longint;
ans:array[1..7]of longint;
procedure init;
begin
assign(input,'friday.in');
assign(output,'friday.out');
reset(input); rewrite(output);
end;
procedure terminate;
begin
close(input); close(output);
halt;
end;
procedure main;
var
year,date,week,rest:longint;
i:longint;
flag:boolean;
begin
readln(n);
year:=1899;
date:=31; week:=7;
fillchar(ans,sizeof(ans),0);
repeat
inc(year);
if ((year mod 100=0)and(year mod 400=0))or ((year mod 100<>0)and(year mod 4=0))
then flag:=true
else flag:=false;
date:=day[12]-date+13;
week:=(week+date) mod 7;
// if week=0 then week:=1;
date:=13;
// writeln(year,' ',date,' ',week);
inc(ans[week]);
for i:=2 to 12 do //枚举月份
begin
if (i=3) and flag then
begin
date:=day[i-1]+1-date+13;
week:=(week+date) mod 7;
// if week=0 then week:=1;
date:=13;
// writeln(year,' ',date,' ',week);
inc(ans[week]);
end
else begin
date:=day[i-1]-date+13;
week:=(week+date) mod 7;
// if week=0 then week:=1;
date:=13;
//writeln(year,' ',date,' ',week);
inc(ans[week]);
end;
end;
until year=1900+n-1;
write(ans[6],' ');
write(ans[0],' ');
for i:=1 to 4 do
write(ans[i],' ');
writeln(ans[5]);
end;
begin
init;
main;
terminate;
end.