friday

描述

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

[编辑] SAMPLE OUTPUT

36 33 34 33 35 35 34
来自"http://www.nocow.cn/index.php/Translate:USACO/friday"
program friday;
var
 n,i,j,s,m,c:integer;
 ans:array[0..6]of longint;
begin
      assign(input,'friday.in');reset(input);
      assign(output,'friday.out');rewrite(output);
      readln(n);

      m:=1;c:=6;

      for i:=1900 to 1900+n-1 do
       begin
           for j:=1 to 12 do
            begin
                case j of
                  1,3,5,7,8,10,12:s:=3;
                  4,6,9,11       :s:=2;
                  2:if (i mod 400=0)or((i mod 4=0)and(i mod 100<>0)) then s:=1 else s:=0;
                  end;
                  inc(ans[(m+c-1)mod 7]);
                  m:=(m+s) mod 7;
            end;
       end;

      write(ans[6]);
      for i:=0 to 5 do write(' ',ans[i]);writeln;
      close(input);
      close(output);
end.

 

posted @ 2012-10-18 02:09  翱翔的感觉  阅读(264)  评论(0)    收藏  举报