#include <stdio.h>
#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 judgeleap(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(y<2010)
return ERROR;
if(m>12||m<0)
return ERROR;
else if(judgeleap(y)==LEAP&&m==2&&d>29) //判断闰年的2月输入是否大于29天
return ERROR;
else if(judgeleap(y)==NONLEAP&&m==2&&d>28) //判断平年的2月输入是否大于28天
return ERROR;
else if(judgeleap(y)==LEAP&&d>Leap[m-1]) //判断闰年输入的天数是否大于输入月的对应天数
return ERROR;
else if(judgeleap(y)==NONLEAP&&d>NonLeap[m-1]) 判断平年输入的天数是否大于输入月的对应天数
return ERROR;
return OK;
}
// 计算输入年月日到当前的总天数,total为地址引用,返回总天数
void Totaldays (int y, int m, int d, int *total)
{
int i;
if (judgeleap(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, month, day;
printf("请输入年月日: \n");
scanf("%d/%d/%d",&year,&month,&day);
while (Judge(year,month,day) == ERROR)
{
printf("请检查输入的年月日是否正确并重新输入: \n");
scanf("%d/%d/%d",&year,&month,&day);
}
Totaldays(year,month,day,&days);
//printf("%d",days);
if (days %5<=3&&days %5!=0)
printf("%d-%d-%d : 打鱼\n",year, month, day);
else
printf("%d-%d-%d : 晒网\n",year, month, day);
getchar();
getchar();
return 0;
}
#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 judgeleap(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(y<2010)
return ERROR;
if(m>12||m<0)
return ERROR;
else if(judgeleap(y)==LEAP&&m==2&&d>29) //判断闰年的2月输入是否大于29天
return ERROR;
else if(judgeleap(y)==NONLEAP&&m==2&&d>28) //判断平年的2月输入是否大于28天
return ERROR;
else if(judgeleap(y)==LEAP&&d>Leap[m-1]) //判断闰年输入的天数是否大于输入月的对应天数
return ERROR;
else if(judgeleap(y)==NONLEAP&&d>NonLeap[m-1]) 判断平年输入的天数是否大于输入月的对应天数
return ERROR;
return OK;
}
// 计算输入年月日到当前的总天数,total为地址引用,返回总天数
void Totaldays (int y, int m, int d, int *total)
{
int i;
if (judgeleap(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, month, day;
printf("请输入年月日: \n");
scanf("%d/%d/%d",&year,&month,&day);
while (Judge(year,month,day) == ERROR)
{
printf("请检查输入的年月日是否正确并重新输入: \n");
scanf("%d/%d/%d",&year,&month,&day);
}
Totaldays(year,month,day,&days);
//printf("%d",days);
if (days %5<=3&&days %5!=0)
printf("%d-%d-%d : 打鱼\n",year, month, day);
else
printf("%d-%d-%d : 晒网\n",year, month, day);
getchar();
getchar();
return 0;
}