#include <stdio.h>
int normalMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int leapMonth[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
int getYear(void)
{
int n;
printf("please input year:");
scanf("%d",&n);
return n;
}
int isLeap(int n)
{
if((n%4==0&&n%100!=0)||n%400==0)
{
return 366;
}
else
{
return 365;
}
}
int weekDays(int year)
{
int i,sum = 0;
for(i = 2008;i<year;i++)
{
sum += isLeap(i);
}
if(sum == 0)
{
sum = 0;
}
else
{
sum = sum%7;
}
switch (sum)
{
case 0:
return 3;
break;
case 1:
return 4;
break;
case 2:
return 5;
break;
case 3:
return 6;
break;
case 4:
return 7;
break;
case 5:
return 1;
break;
case 6:
return 2;
break;
default:
return -10000;
}
}
void darkFriday(int weekday,int year)
{
int week = weekday,i,j,sum = 0;
if(366==isLeap(year))
{
for(i=0;i<12;i++)
{
for(j=1;j<=leapMonth[i];j++)
{
week++;
if(week == 8)
{
week = 1;
}
if(week == 5&& j == 13)
{
sum ++;
}
}
}
}
else
{
for(i=0;i<12;i++)
{
for(j=1;j<=normalMonth[i];j++)
{
week++;
if(week == 8)
{
week = 1;
}
if(week == 5&& j == 13)
{
sum ++;
}
}
}
}
printf("%d\n",sum);
}
int main(void)
{
int year,weekday;
year = getYear();
weekday = weekDays(year);
darkFriday(weekday,year);
return 0;
}
可能不对,你看看吧。楼上的可能更好。
温馨提示:答案为网友推荐,仅供参考