USACO 1.1 黑色星期五 (模拟)
Time Limit:1000MS Memory Limit:65536K
Total Submit:83 Accepted:61
Description
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年是闰年.
请不要预先算好数据!
Input
一个整数n.
Output
七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一.....星期五的次数.
Sample Input
20
Sample Output
36 33 34 33 35 35 34
Source
ljf
-
var x,m,y,d,i,n,j:longint; a:array[1..7]of longint; procedure c(var m:longint); begin d:=1; inc(m); end; begin readln(n); y:=1900; m:=1;d:=1;x:=1;i:=0; fillchar(a,sizeof(a),0); while i<n do begin inc(x); if x=8 then x:=1; case m of 1,3,5,7,8,10,12:if d=31 then c(m) else inc(d); 4,6,9,11:if d=30 then c(m) else inc(d); 2:if (y mod 4=0)and(y mod 100<>0)or(y mod 400=0) then if d=29 then c(m) else inc(d) else if d=28 then c(m) else inc(d); end; if m=13 then begin m:=1; inc(y); inc(i); end; if d=13 then inc(a[x]); end; write(a[6],' ',a[7],' '); for i:=1 to 5 do write(a[i],' '); end.