[USACO1.1]黑色星期五Friday the Thirteenth-洛谷 1202
来源:互联网 发布:淘宝商城笔记本电脑 编辑:程序博客网 时间:2024/05/14 18:24
题目描述13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.这里有一些你要知道的:1、1900年1月1日是星期一.2、4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.3、年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).4、以上规则不适合于世纪年。可以被400整除的世纪年为闰年,否则为平年。所以,1700,1800,1900和2100年是平年,而2000年是闰年.请不要调用现成的函数请不要预先算好数据(就是叫不准打表)!输入输出格式输入格式:一个正整数n.输出格式:输入输出样例输入样例#1:20输出样例#1:36 33 34 33 35 35 34题解:这一道题不断枚举就行了。var i,j,n:integer; day:longint; week:array[0..6] of integer;begin read(n); day:=0; for i:=1900 to 1900+n-1 do for j:=1 to 12 do case j of 1,2,4,6,8,9,11:if (i=1900) and (j=1) then begin day:=day+13; week[day mod 7]:=week[day mod 7]+1; end else begin day:=day+31; week[day mod 7]:=week[day mod 7]+1; end; 3:if (i mod 4=0) and (i mod 100<>0) or (i mod 400=0) then begin day:=day+29; week[day mod 7]:=week[day mod 7]+1; end else begin day:=day+28; week[day mod 7]:=week[day mod 7]+1; end; 5,7,10,12:begin day:=day+30;week[day mod 7]:=week[day mod 7]+1;end; end; write(week[6],' '); for i:=0 to 5 do write(week[i],' '); writeln; end.
0 0
- 洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
- [USACO1.1]黑色星期五Friday the Thirteenth-洛谷 1202
- luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 【模拟】洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 【USACO1.1_3】★Friday the Thirteenth 黑色星期五
- usaco1.1.3 Friday the Thirteenth黑色星期五
- USACO1.1.3 Friday the Thirteenth(黑色星期五)
- [USACO1.1]Friday the Thirteenth
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth 黑色星期五
- USACO1.1 Friday the Thirteenth 比较分析
- Friday the Thirteenth(黑色星期五) USACO
- USACO1.1.3[Friday The Thirteenth]
- USACO1.1.3 Friday the Thirteenth
- USACO1.1.3 - Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth
- 归途与征程 Journey
- 干货:浅谈Spring框架注解的用法分析
- oracle 数据库update失败后 恢复到以前的数据
- 百度测试架构师眼中的百度QA
- win7休眠、待机api
- [USACO1.1]黑色星期五Friday the Thirteenth-洛谷 1202
- Java-读写文件
- C++异常的概念和处理机制
- RPM,SRPM和YUM
- Bzoj 1086: [SCOI2005]王室联邦(分块)
- Hrbust 2292 Tom and Jerry【树上最短路+枚举】
- JS基础学习
- Vue iscroll指令开发
- CentOS 安装 Etherpad (多人一起写)