AcWing 1341 Friday the 13th

Title description:

Is Friday the 13th really unusual?

Is the frequency of Friday on the 13th of each month lower than the other days of the week?

Please write a program to calculate how often the 1313th of each month in NN is Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.

The test period will start on November 11, 1900, and end on December 3131, 1900+N−11900+N−1.

Some additional information to help you solve the problem:

  1. November 11, 1900, 1900 is Monday.
  2. In a year, there are 3030 days in 44 months, 66 months, 99 months, and November and November, 2828 days in a normal year in 22, 2929 days in a leap year, and 31 days in other months.
  3. A year in which the Gregorian calendar is a multiple of 44 and not a multiple of 100, 100 is a leap year. For example, 1992 is a leap year, and 1990 to 1990 is not a leap year.
  4. The Gregorian calendar year is a whole hundred and is a multiple of 400,400 is also a leap year, for example, 1700, 1800, 1900, 2100 is not a leap year, 2000 is a leap year.

Input format

A total of one line, containing an integer NN.

Output format

A total of one line, containing seven integers, separated by a space between the integers, indicating the number of occurrences of Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, and Friday on the 13th.

data range

1≤N≤4001≤N≤400

Input sample:

20

Sample output:

36 33 34 33 35 35 34
#include <iostream>
#include <cstdio>

using namespace std;
int year[2][13] = {
   
   {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

int judge(int x)
{
    return (x % 4 == 0 && x % 100 != 0) || (x % 400 == 0);
}
int n;
int mon, tue, wed, thu, fri, sta, sun;
int a[9];

int main()
{
    scanf("%d", &n);

    int cou = 0;

    for(int y = 1900; y < 1900 + n; y++)
    {
        int yy = 0;
        if(judge(y))
            yy = 1;
        else
            yy = 0;

        for(int m = 1; m <= 12; m ++)
        {
            for(int d = 1; d <= year[yy][m]; d++)
            {
                cou++;
                cou = cou % 7;
                if(d == 13)
                    a[cou] ++;
            }
        }
    }

    printf("%d ", a[6]);
    for(int i = 0; i <= 5; i++)
        printf("%d ", a[i]);
    printf("\n");


    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_44620183/article/details/113399887