1. 蔡勒公式:
来自百度百科
w:星期; w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四,5-星期五,6-星期六
2. 取余运算:
请参考c语言的取模运算 - 迎宾的专栏 - 博客频道 - CSDN.NET
/*
ID: dollarzhaole
PROG: friday
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
int week[8];
int getweek(int c, int y, int m, int d)
{
int w = y + y / 4 + c / 4 - 2 * c + 26 * (m + 1) / 10 + d - 1;
return w;
}
int main()
{
ofstream fout ("friday.out");
ifstream fin ("friday.in");
int n, tmp, year, month, i ,j;
memset(week, 0, sizeof(week));
fin >> n;
for (i = 0; i < n; i++)
for (j = 1; j <= 12; j++)
{
year = i;
month = j;
if (j < 3)
{
year -= 1;
month += 12;
}
tmp = getweek((1900 + year) / 100, (1900 + year) % 100, month, 13) % 7;
if (tmp < 0)
tmp += 7;
week[tmp]++;
}
fout << week[6] << ' ';
for (i = 0; i < 5; i++)
fout << week[i] << ' ';
fout << week[5] << endl;
return 0;
}