USACO成长笔记,不急,慢慢来嘛
/*
ID: 13913351
LANG: C
PROG: friday
*/
#include<stdio.h>
#include<string.h>
int week[7];
int main()
{
FILE *fin = fopen ("friday.in", "r");
FILE *fout = fopen ("friday.out", "w");
memset(week,0,sizeof(week));
int N;
int y,m,d;//年 月 日
int w;//星期
int i,j;
fscanf(fin,"%d",&N);
d=13;
for(i=1900;i<=1900+N-1;i++)
{
int y=i;
for(j=1;j<=12;j++)
{
int m=j;
if(m==1||m==2)
{
m+=12;
y--;
}
w=(y+y/4+y/400-y/100+2*m+3*(m+1)/5+d)%7; //此蔡勒公式公式在1752年9月3日后成立
week[w]++; //week[i]表示 星期 i+1;
if(m>12)y++;//一月,二月计算过后表年份的y减1,在后续计算需要恢复
}
}
fprintf(fout,"%d %d ",week[5],week[6]);
for(i=0;i<4;i++)
{
fprintf(fout,"%d ",week[i]);
}
fprintf(fout,"%d\n",week[4]);
return 0;
}