题设有两个要求:

Do not use any built-in date functions in your computer language.

Don't just precompute the answers, either, please. 

没理解,不管怎么样算是练基本功吧打了好长个程序。

procedure leapyear用于计算当前年是闰年。

procedure unleapyear用于计算当前年非闰年。

start表示当前年Jan. 1st是星期几。

注意一个小细节就是输出顺序:Saturday, Sunday, Monday, Tuesday, ..., Friday.

Friday
const day1:array[1..12] of integer=(31,29,31,30,31,30,31,31,30,31,30,31);
      day2:array[1..12] of integer=(31,28,31,30,31,30,31,31,30,31,30,31);
var a:array[1..7] of longint;
    n,k,start,i:integer;
procedure leapyear(s:integer);
var i:integer;
begin
  s:=(s+12-1) mod 7+1;
  inc(a[s]);
  for i:=1 to 11 do
    begin
      s:=(s+day1[i]-1) mod 7+1;
      inc(a[s]);
    end;
end;

procedure unleapyear(s:integer);
var i:integer;
begin
  s:=(s+12-1) mod 7+1;
  inc(a[s]);
  for i:=1 to 11 do
    begin
      s:=(s+day2[i]-1) mod 7+1;
      inc(a[s]);
    end;
end;

begin
  assign(input,'friday.in');reset(input);
  assign(output,'friday.out');rewrite(output);
  readln(n);
  k:=0;
  start:=1;
  while k<n do
    begin
      if ((k mod 4=0) and (k mod 100<>0)) or ((k+1900) mod 400=0) then
        begin
          leapyear(start);
          start:=(start+366-1) mod 7+1;
        end
      else
        begin
          unleapyear(start);
          start:=(start+365-1) mod 7+1;
        end;
      inc(k);
    end;
  writeln(a[6],' ',a[7],' ',a[1],' ',a[2],' ',a[3],' ',a[4],' ',a[5]);
  close(input);close(output);
end.

 

 posted on 2012-12-14 23:54  Sky-Grey  阅读(133)  评论(0编辑  收藏  举报