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 non-negative and will not exceed 400.

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
由于看错题,可花了我好长一段时间。
View Code

 1 /* 2  ID:10239512 3  PROG:friday 4  LANG:C++     5 */ 6  7 #include<iostream> 8 #include<fstream> 9 using namespace std;10 ifstream fin("friday.in");11 ofstream fout("friday.out");12 13 int n,day,days,year=1900,month,num[8]={0};int x[8]={0,1,3,5,7,8,10,12};14 15 bool leap(int y){16      if((y%4==0&&y%100!=0)||y%400==0)17      return 1;18      return 0;19      }20 bool check(int y){21      int i;22      for(i=1;i<=7;i++)23      if(x[i]==y) return 0;24      return 1;25      }26 27 int main()28 {29     int i,j,k,l;30     fin>>n;31     day=1;32     while(year<1900+n)33     {            34      month=0;35      while(month<=11)36      {37      month++;days=1;38      if(month==2&&leap(year)!=1)39      {40       while(days<=28)41       {42        days++;43        day++;44        if(day>7) day=1;45        if(days==13) num[day]++;46                     }       47       continue;                          48                                 }49      50      if(month==2&&leap(year)==1)51      {52       while(days<=29)53       {54        days++;55        day++;56        if(day>7) day=1;57        if(days==13) num[day]++;58                     }                       59       continue;           60                              }61       62       if(check(month))63       {64        while(days<=30)65        {66         days++;67         day++;68         if(day>7) day=1;69         if(days==13) num[day]++;                   70                      }              71        continue;      72                       }73       74       if(!check(month))75       {76        while(days<=31)77        {78         days++;79         day++;80         if(day>7) day=1;81         if(days==13) num[day]++;                 82                      }   83        continue;                    84                        }85          86                      }87       year++;         88               }89 90     fout<<num[6]<<" "<<num[7]<<" ";91     for(i=1;i<=4;i++)92     fout<<num[i]<<" ";93     fout<<num[5];94     fout<<endl;95     return 0;96     97     }

转载于:https://www.cnblogs.com/noip/archive/2012/02/26/2368676.html

Friday the Thirteenth相关推荐

  1. USACO 1.1 Friday the Thirteenth

    题目来源:USACO 1.1 原题目: Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does ...

  2. Friday the Thirteenth 黑色星期五

    ** Friday the Thirteenth 黑色星期五 ** 解题思路来自NOCOW 题目: 13 号又是星期五是一个不寻常的日子吗? 13 号在星期五比在其他日少吗?为了回答这个问题,写一个程 ...

  3. USACO—1.1.3 Friday the Thirteenth 黑色星期五

    题目描述: 1.1.3 Friday the Thirteenth 黑色星期五 (friday.pas/c/cpp) 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序 ...

  4. USACO黑色星期五Friday the Thirteenth

    黑色星期五Friday the Thirteenth 嗯,虽然很水,但细节是真的多. 我闰年判断错了而且while循环都忘了(伤心) 题目描述 13号又是一个星期五.13号在星期五比在其他日子少吗?为 ...

  5. 黑色星期五Friday the Thirteenth

    题目描述 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900+N- ...

  6. 1.1 Friday the Thirteenth

    2019独角兽企业重金招聘Python工程师标准>>> 以前也听说过黑色星期五,既是13号,又是星期五,这似乎这是个不详的日子,这个题目要我们通过计算了解一下黑色星期五是否有特别之处 ...

  7. USACO 1.0_Friday the Thirteenth

    2019独角兽企业重金招聘Python工程师标准>>> 還好還好蛋沒有粉 /* NAME: zfb2 LANG: C++ TASK: friday */#include <io ...

  8. 洛谷P1202 [USACO1.1]黑色星期五Friday the Thirteenth

    题目描述 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900+N- ...

  9. [USACO1.1]黑色星期五Friday the Thirteenth

    https://www.luogu.org/problemnew/show/P1202 又学了一招重载++ /* *@Author: STZG *@Language: C++ */ #include ...

  10. 洛谷 P1202 模拟 - 黑色星期五 Friday the Thirteenth

    [题目描述] 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900+ ...

最新文章

  1. 反应式系统实现MQTT客户机
  2. 【斗医】【18】Web应用开发20天
  3. 2018,愿跟大家一起成长!
  4. 「MacOS」Mac快捷键
  5. ROS探索总结(五)——创建简单的机器人模型smartcar
  6. RMAN删除归档日志不释放问题
  7. greenplum配置高可用_高可用hadoop集群配置就收藏这一篇,动手搭建Hadoop(5)
  8. c语言用参数确认递归,C语言程序设计(第4章函数)3
  9. 电脑每次开机都要重新设置时间解决方法
  10. RTCM3消息类型介绍
  11. 二级计算机excel以宏保存,excel宏保存 设置宏保存位置的操作方法
  12. js获取0-1之间的随机数,获取1-10之间的随机数
  13. 东周科目三考场5号线_光明东周科目三考场,5条道图纸心得分享
  14. Spring笔记(4) - Spring的编程式事务和声明式事务详解
  15. linux rtsp 获取摄像头视频流,用RTSP流式网络摄像头
  16. 基于leftlet的旅游地图相册
  17. 安全狗西部网络安全运营中心 护航“东数西算”工程安全
  18. 域名被封的表现域名微信不能访问该怎样处理
  19. 诛仙很热,阅文集团的IP产业很冷
  20. dnf跨6服务器不稳定,dnf跨6爆满是什么原因

热门文章

  1. python可以做系统吗_哪个操作系统更适合用来做Python开发
  2. 香港理工计算机qs排名,香港理工大学专业排名一览及最强专业推荐(QS世界大学排名)...
  3. python和c的语法区别_python与c语言的语法有哪些不一样的
  4. label mpchart 饼图_运用matplotlib绘制折线图、散点图、饼图、柱形图的定义代码以及案例详解...
  5. Mysql drop table 原理_mysql事务的实现原理
  6. 五人合伙最佳股份分配_【干货要点】再谈“类直营”——百果园的店长合伙人...
  7. aps后缀是什么文件_今日份知识分享:什么是源文件?
  8. 循环首次适应算法_数据结构与算法之2——排序问题
  9. linux安半程序自动确认,利用system-config-kickstart实现半自动化安装
  10. java select 不是date,iPhonedateselect器,而不是键盘?