[USACO 1.1.3] Friday the Thirteenth
来源:互联网 发布:数组类型转换 编辑:程序博客网 时间:2024/05/02 11:35
[题目描述]
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: zane2951PROG: fridayLANG: 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.
- USACO 1.1.3 Friday the Thirteenth (friday)
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- [USACO 1.1.3] Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO Section 1.1.3 Friday the Thirteenth
- USACO 1.1.3 - Friday the Thirteenth(模拟)
- USACO 1.1-Friday the Thirteenth
- usaco 1.1:Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- usaco/1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1-Friday the Thirteenth
- Android Froyo 源代码编译错误
- 面临抉择而摇摆不定的时候,看看这篇文章——来自台湾清华大学的一位老师
- SQL Select语句完整的执行顺序
- 在N个不同的元素中寻找最大元素
- 广告平台
- [USACO 1.1.3] Friday the Thirteenth
- 获取焦点至文本框的文字后面方法
- Belief
- C语言日历
- JSTL使用总结(2) fmt标签库和fn标签库
- SSDP——Simple Service Discovery Protocol——简单服务发现协议
- 慎思 · 自我
- 标准C/C++程序通过gSOAP调用WebService
- BCB Socket编程指南