My USACO Analysis:Friday the Thirteenth

This is a typical Brute Force.There's nothing to say because this is so easy!All you need is to notice the details.
program friday(input,output);
const
  monthday:array[
1 .. 12 ]of  byte = ( 3 , 0 , 3 , 2 , 3 , 2 , 3 , 3 , 2 , 3 , 2 , 3 );
var
  count:array[
0 .. 6 ]of integer;
  years,year,month,weekday:integer;
function leap(y:integer):boolean;
  begin
    
if  y mod  100 = 0  then
      
if  y mod  400 = 0  then leap: = true   else  leap: = false
    
else
      
if  y mod  4 = 0  then leap: = true   else  leap: = false ;
  end;
begin
  assign(input,
' friday.in ' );
  reset(input);
  readln(input,years);
  close(input);

  fillchar(count,
sizeof (count), 0 );
  weekday:
= 6 ;
  
for  year: = 1900  to  1899 + years  do
    
for  month: = 1  to  12   do  begin
      inc(count[weekday]);
      
if  month = 2  then
        weekday:
= weekday + ord(leap(year))
      
else
        weekday:
= weekday + monthday[month];
      weekday:
= weekday mod  7 ;
    end;

  assign(output,
' friday.out ' );
  rewrite(output);
  write(output,count[
6 ]);
  
for  weekday: = 0  to  5   do
    write(output,
'   ' ,count[weekday]);
  writeln(output);
  close(output);
end.
To download the PASCAL source file:<a href=http://www1.51ok.com/down.do?85FA5DFA93D8E290AA9CFFADC67D36B7>friday.pas</a>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值