USACO Section 1.1-3 Friday the Thirteenth

Friday the Thirteenth 黑色星期五ios

13号又是一个星期五。13号在星期五比在其余日子少吗?为了回答这个问题,写一个程序,要求计算每一个月的十三号落在周一到周日的次数。函数

给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.spa

注意,开始今年是一千九百年,不是1990code

这里有一些你要知道的:blog

一、1900年1月1日是星期一.string

二、4,6,11和9月有30天.其余月份除了2月都有31天.闰年2月有29天,平年2月有28天.it

三、年份能够被4整除的为闰年(1992=4*498 因此 1992年是闰年,可是1990年不是闰年).io

四、以上规则不适合于世纪年。能够被400整除的世纪年为闰年,不然为平年。因此,1700,1800,1900和2100年是平年,而2000年是闰年.class

请不要调用现成的函数stream

请不要预先算好数据(就是叫不许打表)!

PROGRAM NAME: friday

INPUT FORMAT:

(friday.in)

一个正整数n.

OUTPUT FORMAT:

(friday.out)

七个在一行且相分开的整数,它们表明13日是星期六,星期日,星期一...星期五的次数..

SAMPLE INPUT:

20

SAMPLE OUTPUT:

36 33 34 33 35 35 34

      依旧模拟...一天一天的模拟下去
      注意处理几号星期几就行了~~~
 1 /*
 2 ID: jvxie1
 3 PROG: friday
 4 LANG: C++ 
 5 */
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<iostream>
 9 #include<algorithm>
10 using namespace std;
11 int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
12 int day[10];
13 int leap(int year)
14 {
15     if((year%4==0&&year%100!=0)||(year%400==0))
16         return 1;
17     return 0;
18 }
19 int work(int x,int year,int k)
20 {
21     int date=1;
22     for(int i=0;i<12;i++)
23         for(int j=1;j<=month[x][i];j++)
24         {
25             date++;
26             date%=month[x][i];
27             k++;k%=7;
28             if(date==13)
29                 day[k]++;
30         }
31     return k;
32 }
33 int main()
34 {
35     freopen("friday.in","r",stdin);
36     freopen("friday.out","w",stdout);
37     int n,k=1;
38     scanf("%d",&n);
39     for(int i=1900;i<=1900+n-1;i++)
40         k=work(leap(i),i,k);
41     printf("%d %d %d %d %d %d %d\n",day[6],day[0],day[1],day[2],day[3],day[4],day[5]);
42     return 0;
43 }
相关文章
相关标签/搜索