03964.com

文档资料库 文档搜索专家

文档资料库 文档搜索专家

【题目描述】

Friday the Thirteenth

Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday less often than on any other day of the week? To

answer this question, write a program that will compute the frequency(频率) that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is positive(积极的) and will not exceed(超过) 400. Note that the start year is NINETEEN HUNDRED, not 1990. There are few facts you need to know before you can solve this problem: January 1, 1900 was on a Monday. Thirty days has September, April, June, and November, all the rest have 31 except for February which has 28 except in leap(飞跃) years when it has 29. Every year evenly divisible(可分的) by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year) The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year. Do not use any built-in(嵌入的) date functions in your computer language. Don't just precompute the answers, either, please. 【我的思路】 1.第 N 个月的 13 号的星期数取决于上个月的天数和上个月 13 号的星期数。 2.要考虑到 1 月和 2 月的特殊情况。1 月没前驱，所以定义 0~11 月的天数，2 月有闰月，所 以要判定年份。 3.确定星期数的时候一定要取 mod。 4.还有，超坑爹的是它的题目要求的输出是从星期六到星期五，而我一开始就默认为从星期 一开始输出，结果找了好久…… 【code】 //2.3 Friday const day:array[0..11] of integer=(31,31,28,31,30,31,30,31,31,30,31,30); var n,i,j,s,last,today:integer; a:array[1..7] of integer; begin readln(n); fillchar(a,sizeof(a),0); s:=1899; last:=3; for i:=1 to n do begin inc(s); for j:=1 to 12 do

begin today:=(last+day[j-1] mod 7+6) mod 7+1; if ((s mod 4=0) and (s mod 100<>0) or (s mod 100=0) and (s mod 400=0)) and (j=3) then today:=(today+7) mod 7+1; inc(a[today]); last:=today; end; end; for i:=6 to 7 do write(a[i],' '); for i:=1 to 4 do write(a[i],' '); write(a[5]); End. Executing... Test 1: TEST OK [0.003 secs, 276 KB] Test 2: TEST OK [0.003 secs, 276 KB] Test 3: TEST OK [0.000 secs, 276 KB] Test 4: TEST OK [0.000 secs, 276 KB] Test 5: TEST OK [0.003 secs, 276 KB] Test 6: TEST OK [0.003 secs, 276 KB] Test 7: TEST OK [0.000 secs, 276 KB] Test 8: TEST OK [0.000 secs, 276 KB] All tests OK.

相关文章:

- 英语中与星期有关的词语
- 5、 与“星期”名称有关的几个名谚: He that sings on
*Friday*, shall weep on Sunday ; He who laughs on*Friday*will weep on Sunday . 乐极生悲。 ...

- 剑桥少儿英语二级下册第七课原文 It was a Friday afte...
- 剑桥少儿英语二级下册第七课原文 It was a
*Friday*afternoon_少儿英语_幼儿教育_教育专区。本文为广大英语爱好者创造了一些好的英语资料。剑桥...

- Black Friday
- Black
*Friday*_初三英语_英语_初中教育_教育专区。Thanksgiving is always on a Thursday. The day after it has been known as Black*Friday*. It is the start...

- 大学英语听说Unit 8
- C Part B Macro-listening Story 1 An Embarrassing Experience Every
*Friday*morning Mrs. Bell goes to the supermarket and gets the groceries for the week....

- 辅导任务型阅读
- 2011 届高三英语任务型阅读练习 Cash Courses Should schools pay students to come to class?
*Friday*is payday for s2011 届高三英语任务型阅读练习 Cash ...

- 考考你 7个英文脑筋急转弯
- After that, it isn't empty. 答案 6:一本。因为放了一本,包就不空了啊。 ANSWER 7: His horse was called
*Friday*. 答案 7:他的马叫“星期五”。 ...

- 英语一般现在时习题
- On
*Friday*he___去 to a health club. On Saturday he ___打篮球 basketball. And on Sunday he ___骑自行车 his bike. Julie ___a very busy student...

- 2012北京各区一模二模作文范文
- 2012 北京各区一模二模作文范文 2012 海淀一模范文 Last
*Friday*, my class took part in a meaningful and challenging course 2012 北京各区一模二模作文范文 2012...

- 数据分析
- (Monday through
*Friday*) Factor 2: section of newspaper (news, business, sports) Day Monday News 11 8 6 8 Business 10 12 13 11 7 8 11 9 7 8 ...

- USACO题目Friday the Thirteenth及代码解析
- USACO题目
*Friday*the Thirteenth及代码解析_计算机软件及应用_IT/计算机_专业资料。USACO题目*Friday*the Thirteenth及代码解析描述13 号又是一个星期五。13 号在星期五...

更多相关标签:

- Friday 智能门锁
- 第九周作业 Black Friday(1)
- On Friday ________ President Obama
- Conversation OneA. Friday. B. Satur
- WASHINGTON — It is announced Friday
- 1. TODAY, Friday, November 12JAZZ w
- Questions 11-14A. Friday. B. Saturd
- 18.TODAY, Friday, November 12JAZZ w
- A. It’s Friday. B. It matches me we
- when will the woman go() A.Friday