2016-12-26       个评论    来源：huazhen1234的专栏
我要投稿

```#include

#define OK 0
#define ERROR 1
#define NONLEAP 0
#define LEAP 1
int NonLeap[12] = {31,28,31,30,31,30,31,31,30,31,30,31};  //平年天数
int Leap[12] = {31,29,31,30,31,30,31,31,30,31,30,31};  //闰年天数

/*
判断闰年还是平年，闰年返回1,平年返回0
*/
int IsLeap(int y)
{
if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) //闰年判断条件
return LEAP;

return NONLEAP;
}

/*
判断输入的合法性，合法返回0，不合法返回1
*/
int Judge(int y, int m, int d)
{
if (m > 12 || m < 0)
return ERROR;
else if (IsLeap(y) == LEAP && m == 2 && d > 29)  //判断闰年的2月输入是否大于29天
return ERROR;
else if (IsLeap(y) == NONLEAP && m == 2 && d > 28)  //判断平年的2月输入是否大于28天
return ERROR;

return OK;
}

/*
计算输入年月日到当前的总天数，total为地址引用，返回总天数
*/
void Totaldays (int y, int m, int d, int *total)
{
int i;
if (IsLeap(y) == LEAP)
{
for (i = 0; i < m - 1; i ++)
*total += Leap[i];
}
else
{
for (i = 0; i < m - 1; i ++)
*total += NonLeap[i];
}
*total += d;
}

int main ()
{
int days = 0, year, mon, dd;
printf("请输入年月日: \n");
scanf("%d%d%d",&year,&mon,&dd);
while (Judge(year, mon, dd) == ERROR)
{
printf("请检查输入的年月日是否正确并重新输入: \n");
scanf("%d%d%d",&year,&mon,&dd);
}
Totaldays(year, mon, dd, &days);
//printf("%d",days);
if (days % 3 == 1)
printf("%d-%d-%d : 打鱼\n",year, mon, dd);
else
printf("%d-%d-%d : 晒网\n",year, mon, dd);
return 0;
}```