在西方,星期五和数字 13都代表着坏运气,两个不幸的个体最后结合成超级不幸的一天。所以,不管哪个月的十三日又恰逢星期五就叫“黑色星期五”。
要求:输入年份,输出是:判断该年是否包含黑色星期五,如包含,给出具体日期
参考代码:
#include<stdio.h>
int main()
{
int month[10];
int a[13]={0,12,43,71,102,132,163,193,224,255,285,316,346};
int b[13]={0,12,43,72,103,133,164,194,225,256,286,317,347};//闰年时
int n=0,i,year;
scanf("%d",&year);
//能被四整除但不能被四百整除以及能被一百整除的年份是闰年
if(((year%4==0)&&(year%400!=0))||(year%100==0))//闰年时
{
for(i=1;i<=12;i++)
{
if((year*365+(year-1)/4-year/100+year/400+b[i])%7==5)
{
month[n]=i;
n++;
}
}
}
else//平年
{
for(i=1;i<=12;i++)
{
if((year*365+year/4-year/100+year/400+a[i])%7==5)
{
month[n]=i;
n++;
}
}
}
if(n==0){
printf("There is %d Black Friday in year %d.\n",n,year);
}else{
if(n==1)
{
printf("There is %d Black Friday in year %d.\nIt is:\n",n,year);
printf("%d/%d/%d\n",year,month[0],13);
}
else
{
printf("There are %d Black Fridays in year %d.\nThey are:\n",n,year);
for(i=0;i<n;i++)
printf("%d/%d/%d\n",year,month[i],13);
}
}
return 0;
}