这题主要是需要开一个二维数组,巧妙解决闰年的问题。然后判断闰年之后直接去数组里取每个月的天数就好。
然后就是模拟,自增,取余。
先开始忘写fun()的返回值了,所以运行样例的结果总是错。。。很尴尬。
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int n;
// int cur;
int day[8];
int a[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}};
int leap(int cur) {
if((cur % 4 == 0 && cur % 100 != 0) || cur % 400 == 0 )
return 1;
return 0;
}
int fun(int h, int year, int k)
{
int date = 1;
for(int i = 0; i < 12; i++)
for(int j = 0; j < a[h][i]; j++) {
date++;
date %= a[h][i];
k++;
k %= 7;
if(date == 13) day[k]++;
}
return k;
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int cur, k;
scanf("%d", &n);
memset(day, 0, sizeof(day));
cur = 1900 + n - 1; k = 1;
for(int i = 1900; i <= cur; i++)
k = fun(leap(i), i, k);
printf("%d %d %d %d %d %d %d\n", day[6], day[0], day[1], day[2], day[3], day[4], day[5]);
return 0;
}
/**/