描述
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:
(file friday.in)
一个整数n.
OUTPUT FORMAT:
(file friday.out)
七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一...星期五的次数.
SAMPLE INPUT
20
SAMPLE OUTPUT
36 33 34 33 35 35 34
我的程序
{
ID:cxj6661
PROB:friday
LANG:PASCAL
}
Program friday;
var a:array[0..400,1..12]of integer;
sl:array[1..7]of integer;
i,j,p,lp,n,li:longint;
Function getDay(p,q:integer):integer;
var i:integer;
begin
i:=1900+p;
if (q=1)or(q=3)or(q=5)or(q=7)or(q=8)or(q=10)or(q=12) then exit(31);
if (q=2) then
if ((i mod 100=0)and(i mod 400=0))or((i mod 100<>0)and(i mod 4=0)) then exit(29) else exit(28);
exit(30);
end;
begin
assign(input,'friday.in'); reset(input);
assign(output,'friday.out'); rewrite(output);
fillchar(a,sizeof(a),0);
a[0,1]:=6;
readln(n);
for i:=0 to n-1 do
begin
if i=0 then p:=2 else p:=1;
for j:=p to 12 do
begin
if j=1 then begin lp:=12; li:=i-1 end else begin lp:=j-1; li:=i; end;
a[i,j]:=((getDay(i,lp)mod 7+a[li,lp])-1)mod 7+1;
end;
end;
fillchar(sl,sizeof(sl),0);
for i:=1 to 12 do
begin
for j:=0 to n-1 do
begin
inc(sl[a[j,i]]);
end;
end;
for i:=1 to 7 do
begin
if i<>7 then write(sl[((i+4)mod 7+1)],' ') else writeln(sl[((i+4)mod 7 +1)]);
end;
close(output);
end.