AcWing 1341. 十三号星期五
原题链接
简单
作者:
我要出去乱说
,
2021-02-06 00:43:09
,
所有人可见
,
阅读 375
#include <iostream>
#include <algorithm>
using namespace std;
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int weekday[7]; //记录黑色日每周出现次数
int main()
{
int n;
cin >> n;
int days = 0; //days表示每个月第一天距1900年多少天
for (int year = 1900; year < 1900 + n; year ++ )
{
for (int i = 1; i <= 12; i ++ )
{
weekday[(days + 12) % 7] ++ ; //记录本月13号是星期几
days += month[i];
if (i == 2)
{ //判断闰年
if (year % 100 && year % 4 == 0 || year % 400 == 0) days ++ ;
}
}
}
for (int i = 5, j = 0; j < 7; i = (i + 1) % 7, j ++ ) //从周六开始遍历一轮
cout << weekday[i] << ' ';
cout << endl;
return 0;
}