Friday the Thirteenth Black Friday

Description

The 13th is the 5th of the week again. Is the 13th less on Friday than on other days? To answer this question, write a program that asks to count the number of times the thirteenth falls from Monday to Sunday each month. Given a period of N years, it is required to calculate the number of times the thirteenth falls on Monday to Sunday in the period from January 1, 1900 to December 31, 1900+N-1, N is a positive integer and not greater than 400. Here Here are some things you need to know: January 1, 1900 is a Monday. April, June, November and September have 30 days. All other months except February have 31 days. February has 29 days in leap years and February in normal years 28 days. The year divisible by 4 is a leap year (1992=4*498, so 1992 is a leap year, but 1990 is not a leap year) The above rules are not applicable to century years. Century years that are divisible by 400 are leap years, otherwise they are ordinary years . So, 1700, 1800, 1900 and 2100 are normal years, and 2000 is a leap year. Please do not pre-calculate the data (that is, not allowed to type 0.0)!

Input

a positive integer n.

Output

Seven separate integers on a line representing the number of times the 13th is Saturday, Sunday, Monday...Friday.

Sample Input

20

Sample Output

36 33 34 33 35 35 34



 1 #include<stdio.h>
 2 int day(int y,int m)
 3 {
 4     if((y%4==0&&y%100!=0)||y%400==0)
 5     {
 6         if(m==2)
 7             return 29;
 8     }
 9     else
10     {
11         if(m==2)
12             return 28;
13     }
 14      if (m== 1 ||m== 3 ||m== 5 ||m == 7 ||m== 8 ||m== 10 ||m== 12 ) /// One three 578015 
return 31 ;
 16          else 17 return 30 ;
 18 }
 19 int main()
 20 { 21 int n
 , i ,j,m= 13 ; /// The first 13th number 22 int num[ 7 ] ={ 0 };
 23      
                  
          scanf("%d",&n);
24     for(i=1900;i<=1900+n-1;i++)
25     {
26         for(j=1;j<=12;j++)
27         {
28             num[m%7]++;
29             m=m+day(i,j);
30         }
31     }
32     printf("%d %d",num[6],num[0]);
33     for(i=1;i<=5;i++)
34     {
35         printf(" %d",num[i]);
36     }
37     return 0;
38 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325265725&siteId=291194637