[USACO 1.1.3] Friday the Thirteenth

[题目描述]

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


[解题思路]

依旧是模拟,只需要注意闰年闰月的处理即可。


[Code]

{
ID: zane2951
PROG: friday
LANG: PASCAL
}

program friday;
const
   days:array[1..12] of longint=(31,28,31,30,31,30,31,31,30,31,30,31);

var
   ans:array[0..8] of longint;
   n,goal,year,mon,now,i,ce:longint;

//----------main-----------
begin
   assign(input,'friday.in'); reset(input);
   assign(output,'friday.out'); rewrite(output);
   readln(n); goal:=1900+n-1;
   year:=1900; now:=0;
   while year<=goal do
      begin
         mon:=1;
         while mon<=12 do
            begin
               ce:=days[mon];
               if year mod 100=0 then
                  begin
                     if (year mod 400=0) and (mon=2) then inc(ce);
                  end
               else if year mod 4=0 then if mon=2 then inc(ce);
               for i:=1 to ce do
                  begin
                     inc(now);
                     if now>7 then now:=1;
                     if i=13 then inc(ans[now]);
                  end;
               inc(mon);
            end;
         inc(year);
      end;
   for i:=6 to 7 do write(ans[i],'':1);
   for i:=1 to 4 do write(ans[i],'':1);
   writeln(ans[5]);
   close(input); close(output);
end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值