1990 、1、13 在 Saturday
用next 过程 计算下一个 13号 在 星期几
具体看程序
{
ID: yaoyuan4
PROG: friday
LANG: PASCAL
}
Program friday;
const
mo : array[1..12] of longint =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
inf = 'friday.in'; outf = 'friday.out';
var
n, y, m, w : longint;
f : array[1..7] of longint;
Procedure init;
begin
assign(input, inf); reset(input);
readln(n);
close(input);
y := 1900;
m := 1;
w := 6;
fillchar(f, sizeof(f), 0);
end;
Function run(a : longint) : boolean;
var
ok : boolean;
begin
ok := false;
if ((a mod 4 = 0) and (a mod 100 <> 0)) or (a mod 400 = 0) then
ok := true;
exit(ok);
end;
Procedure next(var a, b, r : longint);
var
t : longint;
begin
t := mo[b];
if (run(a)) and (b = 2) then inc(t);
inc(b);
if b = 13 then
begin
inc(a);
b := 1;
end;
r := (r + t) mod 7;
if r = 0 then r := 7;
end;
Procedure work;
begin
repeat
inc(f[w]);
next(y, m, w);
until (y = 1900 + n) and (m = 1);
end;
Procedure print;
var
i : longint;
begin
assign(output, outf); rewrite(output);
write(f[6],' ',f[7]);
for i := 1 to 5 do
write(' ',f[i]);
writeln;
close(output);
end;
begin
init;
work;
print;
end.