Friday the 13th

#include<fstream>
using namespace std;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
bool isleep(int year)
{
	if((year%100!=0 && year%4==0)||(year%400==0))
		return true;
	else
		return false;
}
int main()
{
	ifstream fin ("friday.in");
	ofstream fout ("friday.out");
	int n,k,year,days;
	fin>>n;
	int week[7]={0};
	int c=0;
	for(int i=0;i<n;i++)
	{
		if(isleep(i+1900))
		{
			year=366;
			month[1]=29;
		}
		else
		{
			year=365;
			month[1]=28;
		}
		week[(c+13)%7]++;
		k=c+13;
		for(int j=1;j<12;j++)
		{
			k+=month[j-1];
			week[k%7]++;
		}
		days=c+year;
		c=days%7;
	}
	for(int t=-1;t<=5;t++)
	{
		if(t!=5)
			fout<<week[(t+7)%7]<<" ";
		else
			fout<<week[(t+7)%7];
	}
	fout<<endl;
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章