USACO-Friday the Thirteenth(黑色星期五)-Section1.2<3>

【英文原题】

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.

PROGRAM NAME: friday

INPUT FORMAT

One line with the integer N.

SAMPLE INPUT (file friday.in)

20

OUTPUT FORMAT

Seven space separated integers on one line. These integers represent the number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, ..., Friday.

SAMPLE OUTPUT (file friday.out)

36 33 34 33 35 35 34

【中文翻译】

题目描述

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
思路:纯模拟题,从1900年开始一天一天地判断即可。
不要看代码长,其实只要写好一个月的,复制粘贴23次修改一下即可!
 
代码如下:
  1 #include<stdio.h>
  2 bool isLeapYear(int year)//判断闰年 
  3 {
  4     if(year == 1900 || year == 2000 || year == 2100 || year == 2200 || year == 2300 || year == 2400 || year == 2500){
  5         if(year % 400 == 0)
  6         {
  7             return true;
  8         }
  9     }
 10     else if(year % 4 == 0)
 11     {
 12         return true;//是闰年 
 13     }
 14     return false;//不是闰年 
 15 }
 16 int main(){
 17     int n;
 18     scanf("%d",&n);
 19     int ans[7] = {0};
 20     int day = 1;
 21     for(int i = 1900;i < 1900 + n;i++)
 22     {
 23         if(isLeapYear(i) == false)
 24         {
 25             for(int j = 0;j < 31;j++)
 26             {//平年1月 
 27                 if(j == 13){
 28                     if(day == 1){
 29                         ans[day - 1]++;
 30                     }else if(day == 2){
 31                         ans[day - 1]++;
 32                     }else if(day == 3){
 33                         ans[day - 1]++;
 34                     }else if(day == 4){
 35                         ans[day - 1]++;
 36                     }else if(day == 5){
 37                         ans[day - 1]++;
 38                     }else if(day == 6){
 39                         ans[day - 1]++;
 40                     }else if(day == 7){
 41                         ans[day - 1]++;
 42                     }
 43                 }
 44                 day++;
 45                 if(day > 7){
 46                     day = 1;
 47                 }
 48             }
 49             for(int j = 0;j < 28;j++){//平年2月 
 50                 if(j == 13){
 51                     if(day == 1){
 52                         ans[day - 1]++;
 53                     }else if(day == 2){
 54                         ans[day - 1]++;
 55                     }else if(day == 3){
 56                         ans[day - 1]++;
 57                     }else if(day == 4){
 58                         ans[day - 1]++;
 59                     }else if(day == 5){
 60                         ans[day - 1]++;
 61                     }else if(day == 6){
 62                         ans[day - 1]++;
 63                     }else if(day == 7){
 64                         ans[day - 1]++;
 65                     }
 66                 }
 67                 day++;
 68                 if(day > 7){
 69                     day = 1;
 70                 }
 71             }
 72             for(int j = 0;j < 31;j++){//平年3月 
 73                 if(j == 13){
 74                     if(day == 1){
 75                         ans[day - 1]++;
 76                     }else if(day == 2){
 77                         ans[day - 1]++;
 78                     }else if(day == 3){
 79                         ans[day - 1]++;
 80                     }else if(day == 4){
 81                         ans[day - 1]++;
 82                     }else if(day == 5){
 83                         ans[day - 1]++;
 84                     }else if(day == 6){
 85                         ans[day - 1]++;
 86                     }else if(day == 7){
 87                         ans[day - 1]++;
 88                     }
 89                 }
 90                 day++;
 91                 if(day > 7){
 92                     day = 1;
 93                 }
 94             }
 95             for(int j = 0;j < 30;j++){//平年4月 
 96                 if(j == 13){
 97                     if(day == 1){
 98                         ans[day - 1]++;
 99                     }else if(day == 2){
100                         ans[day - 1]++;
101                     }else if(day == 3){
102                         ans[day - 1]++;
103                     }else if(day == 4){
104                         ans[day - 1]++;
105                     }else if(day == 5){
106                         ans[day - 1]++;
107                     }else if(day == 6){
108                         ans[day - 1]++;
109                     }else if(day == 7){
110                         ans[day - 1]++;
111                     }
112                 }
113                 day++;
114                 if(day > 7){
115                     day = 1;
116                 }
117             }
118             for(int j = 0;j < 31;j++){//平年5月 
119                 if(j == 13){
120                     if(day == 1){
121                         ans[day - 1]++;
122                     }else if(day == 2){
123                         ans[day - 1]++;
124                     }else if(day == 3){
125                         ans[day - 1]++;
126                     }else if(day == 4){
127                         ans[day - 1]++;
128                     }else if(day == 5){
129                         ans[day - 1]++;
130                     }else if(day == 6){
131                         ans[day - 1]++;
132                     }else if(day == 7){
133                         ans[day - 1]++;
134                     }
135                 }
136                 day++;
137                 if(day > 7){
138                     day = 1;
139                 }
140             }
141             for(int j = 0;j < 30;j++){//平年6月 
142                 if(j == 13){
143                     if(day == 1){
144                         ans[day - 1]++;
145                     }else if(day == 2){
146                         ans[day - 1]++;
147                     }else if(day == 3){
148                         ans[day - 1]++;
149                     }else if(day == 4){
150                         ans[day - 1]++;
151                     }else if(day == 5){
152                         ans[day - 1]++;
153                     }else if(day == 6){
154                         ans[day - 1]++;
155                     }else if(day == 7){
156                         ans[day - 1]++;
157                     }
158                 }
159                 day++;
160                 if(day > 7){
161                     day = 1;
162                 }
163             }
164             for(int j = 0;j < 31;j++){//平年7月 
165                 if(j == 13){
166                     if(day == 1){
167                         ans[day - 1]++;
168                     }else if(day == 2){
169                         ans[day - 1]++;
170                     }else if(day == 3){
171                         ans[day - 1]++;
172                     }else if(day == 4){
173                         ans[day - 1]++;
174                     }else if(day == 5){
175                         ans[day - 1]++;
176                     }else if(day == 6){
177                         ans[day - 1]++;
178                     }else if(day == 7){
179                         ans[day - 1]++;
180                     }
181                 }
182                 day++;
183                 if(day > 7){
184                     day = 1;
185                 }
186             }
187             for(int j = 0;j < 31;j++){//平年8月 
188                 if(j == 13){
189                     if(day == 1){
190                         ans[day - 1]++;
191                     }else if(day == 2){
192                         ans[day - 1]++;
193                     }else if(day == 3){
194                         ans[day - 1]++;
195                     }else if(day == 4){
196                         ans[day - 1]++;
197                     }else if(day == 5){
198                         ans[day - 1]++;
199                     }else if(day == 6){
200                         ans[day - 1]++;
201                     }else if(day == 7){
202                         ans[day - 1]++;
203                     }
204                 }
205                 day++;
206                 if(day > 7){
207                     day = 1;
208                 }
209             }
210             for(int j = 0;j < 30;j++){//平年9月 
211                 if(j == 13){
212                     if(day == 1){
213                         ans[day - 1]++;
214                     }else if(day == 2){
215                         ans[day - 1]++;
216                     }else if(day == 3){
217                         ans[day - 1]++;
218                     }else if(day == 4){
219                         ans[day - 1]++;
220                     }else if(day == 5){
221                         ans[day - 1]++;
222                     }else if(day == 6){
223                         ans[day - 1]++;
224                     }else if(day == 7){
225                         ans[day - 1]++;
226                     }
227                 }
228                 day++;
229                 if(day > 7){
230                     day = 1;
231                 }
232             }
233             for(int j = 0;j < 31;j++){//平年10月 
234                 if(j == 13){
235                     if(day == 1){
236                         ans[day - 1]++;
237                     }else if(day == 2){
238                         ans[day - 1]++;
239                     }else if(day == 3){
240                         ans[day - 1]++;
241                     }else if(day == 4){
242                         ans[day - 1]++;
243                     }else if(day == 5){
244                         ans[day - 1]++;
245                     }else if(day == 6){
246                         ans[day - 1]++;
247                     }else if(day == 7){
248                         ans[day - 1]++;
249                     }
250                 }
251                 day++;
252                 if(day > 7){
253                     day = 1;
254                 }
255             }
256             for(int j = 0;j < 30;j++){//平年11月 
257                 if(j == 13){
258                     if(day == 1){
259                         ans[day - 1]++;
260                     }else if(day == 2){
261                         ans[day - 1]++;
262                     }else if(day == 3){
263                         ans[day - 1]++;
264                     }else if(day == 4){
265                         ans[day - 1]++;
266                     }else if(day == 5){
267                         ans[day - 1]++;
268                     }else if(day == 6){
269                         ans[day - 1]++;
270                     }else if(day == 7){
271                         ans[day - 1]++;
272                     }
273                 }
274                 day++;
275                 if(day > 7){
276                     day = 1;
277                 }
278             }
279             for(int j = 0;j < 31;j++){//平年12月 
280                 if(j == 13){
281                     if(day == 1){
282                         ans[day - 1]++;
283                     }else if(day == 2){
284                         ans[day - 1]++;
285                     }else if(day == 3){
286                         ans[day - 1]++;
287                     }else if(day == 4){
288                         ans[day - 1]++;
289                     }else if(day == 5){
290                         ans[day - 1]++;
291                     }else if(day == 6){
292                         ans[day - 1]++;
293                     }else if(day == 7){
294                         ans[day - 1]++;
295                     }
296                 }
297                 day++;
298                 if(day > 7){
299                     day = 1;
300                 }
301             }
302         }
303             else{
304             for(int j = 0;j < 31;j++){//闰年1月 
305                 if(j == 13){
306                     if(day == 1){
307                         ans[day - 1]++;
308                     }else if(day == 2){
309                         ans[day - 1]++;
310                     }else if(day == 3){
311                         ans[day - 1]++;
312                     }else if(day == 4){
313                         ans[day - 1]++;
314                     }else if(day == 5){
315                         ans[day - 1]++;
316                     }else if(day == 6){
317                         ans[day - 1]++;
318                     }else if(day == 7){
319                         ans[day - 1]++;
320                     }
321                 }
322                 day++;
323                 if(day > 7){
324                     day = 1;
325                 }
326             }
327             for(int j = 0;j < 29;j++){//闰年2月 
328                 if(j == 13){
329                     if(day == 1){
330                         ans[day - 1]++;
331                     }else if(day == 2){
332                         ans[day - 1]++;
333                     }else if(day == 3){
334                         ans[day - 1]++;
335                     }else if(day == 4){
336                         ans[day - 1]++;
337                     }else if(day == 5){
338                         ans[day - 1]++;
339                     }else if(day == 6){
340                         ans[day - 1]++;
341                     }else if(day == 7){
342                         ans[day - 1]++;
343                     }
344                 }
345                 day++;
346                 if(day > 7){
347                     day = 1;
348                 }
349             }
350             for(int j = 0;j < 31;j++){//闰年3月 
351                 if(j == 13){
352                     if(day == 1){
353                         ans[day - 1]++;
354                     }else if(day == 2){
355                         ans[day - 1]++;
356                     }else if(day == 3){
357                         ans[day - 1]++;
358                     }else if(day == 4){
359                         ans[day - 1]++;
360                     }else if(day == 5){
361                         ans[day - 1]++;
362                     }else if(day == 6){
363                         ans[day - 1]++;
364                     }else if(day == 7){
365                         ans[day - 1]++;
366                     }
367                 }
368                 day++;
369                 if(day > 7){
370                     day = 1;
371                 }
372             }
373             for(int j = 0;j < 30;j++){//闰年4月 
374                 if(j == 13){
375                     if(day == 1){
376                         ans[day - 1]++;
377                     }else if(day == 2){
378                         ans[day - 1]++;
379                     }else if(day == 3){
380                         ans[day - 1]++;
381                     }else if(day == 4){
382                         ans[day - 1]++;
383                     }else if(day == 5){
384                         ans[day - 1]++;
385                     }else if(day == 6){
386                         ans[day - 1]++;
387                     }else if(day == 7){
388                         ans[day - 1]++;
389                     }
390                 }
391                 day++;
392                 if(day > 7){
393                     day = 1;
394                 }
395             }
396             for(int j = 0;j < 31;j++){//闰年5月 
397                 if(j == 13){
398                     if(day == 1){
399                         ans[day - 1]++;
400                     }else if(day == 2){
401                         ans[day - 1]++;
402                     }else if(day == 3){
403                         ans[day - 1]++;
404                     }else if(day == 4){
405                         ans[day - 1]++;
406                     }else if(day == 5){
407                         ans[day - 1]++;
408                     }else if(day == 6){
409                         ans[day - 1]++;
410                     }else if(day == 7){
411                         ans[day - 1]++;
412                     }
413                 }
414                 day++;
415                 if(day > 7){
416                     day = 1;
417                 }
418             }
419             for(int j = 0;j < 30;j++){//闰年6月 
420                 if(j == 13){
421                     if(day == 1){
422                         ans[day - 1]++;
423                     }else if(day == 2){
424                         ans[day - 1]++;
425                     }else if(day == 3){
426                         ans[day - 1]++;
427                     }else if(day == 4){
428                         ans[day - 1]++;
429                     }else if(day == 5){
430                         ans[day - 1]++;
431                     }else if(day == 6){
432                         ans[day - 1]++;
433                     }else if(day == 7){
434                         ans[day - 1]++;
435                     }
436                 }
437                 day++;
438                 if(day > 7){
439                     day = 1;
440                 }
441             }
442             for(int j = 0;j < 31;j++){//闰年7月 
443                 if(j == 13){
444                     if(day == 1){
445                         ans[day - 1]++;
446                     }else if(day == 2){
447                         ans[day - 1]++;
448                     }else if(day == 3){
449                         ans[day - 1]++;
450                     }else if(day == 4){
451                         ans[day - 1]++;
452                     }else if(day == 5){
453                         ans[day - 1]++;
454                     }else if(day == 6){
455                         ans[day - 1]++;
456                     }else if(day == 7){
457                         ans[day - 1]++;
458                     }
459                 }
460                 day++;
461                 if(day > 7){
462                     day = 1;
463                 }
464             }
465             for(int j = 0;j < 31;j++){//闰年8月 
466                 if(j == 13){
467                     if(day == 1){
468                         ans[day - 1]++;
469                     }else if(day == 2){
470                         ans[day - 1]++;
471                     }else if(day == 3){
472                         ans[day - 1]++;
473                     }else if(day == 4){
474                         ans[day - 1]++;
475                     }else if(day == 5){
476                         ans[day - 1]++;
477                     }else if(day == 6){
478                         ans[day - 1]++;
479                     }else if(day == 7){
480                         ans[day - 1]++;
481                     }
482                 }
483                 day++;
484                 if(day > 7){
485                     day = 1;
486                 }
487             }
488             for(int j = 0;j < 30;j++){//闰年9月 
489                 if(j == 13){
490                     if(day == 1){
491                         ans[day - 1]++;
492                     }else if(day == 2){
493                         ans[day - 1]++;
494                     }else if(day == 3){
495                         ans[day - 1]++;
496                     }else if(day == 4){
497                         ans[day - 1]++;
498                     }else if(day == 5){
499                         ans[day - 1]++;
500                     }else if(day == 6){
501                         ans[day - 1]++;
502                     }else if(day == 7){
503                         ans[day - 1]++;
504                     }
505                 }
506                 day++;
507                 if(day > 7){
508                     day = 1;
509                 }
510             }
511             for(int j = 0;j < 31;j++){//闰年10月 
512                 if(j == 13){
513                     if(day == 1){
514                         ans[day - 1]++;
515                     }else if(day == 2){
516                         ans[day - 1]++;
517                     }else if(day == 3){
518                         ans[day - 1]++;
519                     }else if(day == 4){
520                         ans[day - 1]++;
521                     }else if(day == 5){
522                         ans[day - 1]++;
523                     }else if(day == 6){
524                         ans[day - 1]++;
525                     }else if(day == 7){
526                         ans[day - 1]++;
527                     }
528                 }
529                 day++;
530                 if(day > 7){
531                     day = 1;
532                 }
533             }
534             for(int j = 0;j < 30;j++){//闰年11月 
535                 if(j == 13){
536                     if(day == 1){
537                         ans[day - 1]++;
538                     }else if(day == 2){
539                         ans[day - 1]++;
540                     }else if(day == 3){
541                         ans[day - 1]++;
542                     }else if(day == 4){
543                         ans[day - 1]++;
544                     }else if(day == 5){
545                         ans[day - 1]++;
546                     }else if(day == 6){
547                         ans[day - 1]++;
548                     }else if(day == 7){
549                         ans[day - 1]++;
550                     }
551                 }
552                 day++;
553                 if(day > 7){
554                     day = 1;
555                 }
556             }
557             for(int j = 0;j < 31;j++){//闰年12月 
558                 if(j == 13){
559                     if(day == 1){
560                         ans[day - 1]++;
561                     }else if(day == 2){
562                         ans[day - 1]++;
563                     }else if(day == 3){
564                         ans[day - 1]++;
565                     }else if(day == 4){
566                         ans[day - 1]++;
567                     }else if(day == 5){
568                         ans[day - 1]++;
569                     }else if(day == 6){
570                         ans[day - 1]++;
571                     }else if(day == 7){
572                         ans[day - 1]++;
573                     }
574                 }
575                 day++;
576                 if(day > 7){
577                     day = 1;
578                 }
579             }
580         }
581     }
582     printf("%d ",ans[6]);
583     printf("%d ",ans[0]);
584     printf("%d ",ans[1]);
585     printf("%d ",ans[2]);
586     printf("%d ",ans[3]);
587     printf("%d ",ans[4]);
588     printf("%d ",ans[5]);
589     printf("\n");
590     return 0;
591 }
posted @ 2018-03-03 21:21  Memoryヾノ战心  阅读(424)  评论(0编辑  收藏  举报