三天打鱼两天晒网 判断从2010开始后的每一天是在打鱼还是晒网

三天打鱼两天晒网
判断从2010开始后的每一天是在打鱼还是晒网
这个程序增加了一些错误时间判断与提示等

//判断从2010开始后的每一天是在打鱼还是晒网
#include <stdio.h>
int main()
 {
	int year, month, day;
//	int year; int month; int day;
	printf("Please enter the date:( order as year month day )"); 
	scanf ("%d%d%d",&year,&month,&day);
	int a, b, c,sum, t, l;
//	int a; int b; int k; int sum; int t; int l;
	int p = 0,q = 0, i = 2010;

	//判断数字是否合法
	//判断年是否合法
	if ( year < 2010 ) {
		printf("您的输入有误\n");
		return 0;
	}
	//判断月 与 日 是否合法
	if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {	//判断天数为31的月份
		if (day < 1 || day > 31) {
			printf ("您的输入有误\n");
			return 0;
		}
	}

	if ( month == 4 || month == 6 || month == 9 || month == 11) { //判断天数为30的月份
		if (day < 1 || day > 30) {
			printf ("您的输入有误\n");
			return 0;
		}
	}

	if ((year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0) { //判断天数为28,29的月份
		if (month == 2 && day > 29 ) {
			printf("您的输入有误\n");
			return 0;
		}
	} else if (month == 2 && day >= 28 ) {
		printf ("您的输入有误\n");
		return 0;
	}

	//月份b 值的初始化
	if (((year - 1) % 4 == 0 && (year - 1) % 100 != 0 ) || (year -1) % 400 == 0) {
		l = 29;
	} else {
		l = 28;
	}

	b = month - 1;

	switch(b) {
		case 0:
			c = 0;
			break;
		case 1:
			c = 31;
			break;
		case 2:
			c = 31 + l;
			break;
		case 3:
			c = 31 + l + 31;
			break;
		case 4:
			c = 31 + l + 31 + 30;
			break;
		case 5:
			c = 31 + l + 31 + 30 + 31;
			break;
		case 6:
			c = 31 + l + 31 + 30 + 31 +30;
			break;
		case 7:
			c = 31 + l + 31 + 30 + 31 +30 + 31;
			break;
		case 8:
			c = 31 + l + 31 + 30 + 31 +30 + 31 + 31;
			break;
		case 9:
			c = 31 + l + 31 + 30 + 31 +30 + 31 + 31 + 30;
			break;
		case 10:
			c = 31 + l + 31 + 30 + 31 +30 + 31 + 31 + 30 + 31;
			break;
		case 11:
			c = 31 + l + 31 + 30 + 31 +30 + 31 + 31 + 30 + 31 + 30;
			break;
	}

	if (year > 2010) {
		for (i=2010; i < year; ++i) {
			if (((year - 1) % 4 == 0 && (year - 1) % 100 != 0 ) || (year -1) % 400 == 0) {
				p = p + 1;
			} else {
				q = q + 1;
			}
			a = p * 366 + q * 365;
		}
	}

	sum = a + c + day;

	t = t % 5;

	if (t == 1 || t == 2 || t == 3)
		printf ("打鱼\n");
	else
		printf ("晒网\n");

//	printf("%d\n",sum);
//	printf ("\n");
//	printf ("%d\n",a);
//	printf ("%d\n",b);
//	printf ("%d\n",c);
//	printf ("%d\n",day);

	return 0;
}
发布了22 篇原创文章 · 获赞 39 · 访问量 4054

猜你喜欢

转载自blog.csdn.net/weixin_44895666/article/details/100787843