USACO Section 1.1 : Friday the Thirteenth
# include <stdio.h>
int leap(int year)
{
if (((year%4==0)&&(year%100!=0))||(year%400==0))
return (1);
else
return (0);
}
main ()
{
FILE *in=fopen("friday.in","r");
FILE *out=fopen("friday.out","w");
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int week[8]={0};
int year,i,j,data=13;
fscanf (in,"%d",&year);
year+=1900;
for (i=1900;i<year;i++)
{
for (j=1;j<=12;j++)
{
data=data%7;
if (data==0) week[7]++;
else week[data]++;
data+=month[j];
if ((j==2)&&(leap(i)==1))
data++;
}
}
fprintf (out,"%d %d",week[6],week[7]);
for (i=1;i<=5;i++)
fprintf (out," %d",week[i]);
fprintf (out,"\n");
fclose (in);
fclose (out);
exit(0);
}
int leap(int year)
{
if (((year%4==0)&&(year%100!=0))||(year%400==0))
return (1);
else
return (0);
}
main ()
{
FILE *in=fopen("friday.in","r");
FILE *out=fopen("friday.out","w");
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int week[8]={0};
int year,i,j,data=13;
fscanf (in,"%d",&year);
year+=1900;
for (i=1900;i<year;i++)
{
for (j=1;j<=12;j++)
{
data=data%7;
if (data==0) week[7]++;
else week[data]++;
data+=month[j];
if ((j==2)&&(leap(i)==1))
data++;
}
}
fprintf (out,"%d %d",week[6],week[7]);
for (i=1;i<=5;i++)
fprintf (out," %d",week[i]);
fprintf (out,"\n");
fclose (in);
fclose (out);
exit(0);
}