/*42、任务名称:打鱼还是晒网 任务要求: 中国有句俗语叫“三天打鱼两天晒网”。某人从 1990 年 1 月 1 日起开始“三天打鱼 两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。 */ #include<stdio.h> #include<stdlib.h> void fish(int year, int ?month, int ?day); void main() { ?? ?int i, j; ?? ?int year, month, day; ?? ?int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; ?? ?printf("请输入年月日\n"); ?? ?printf("年:"); ?? ?scanf("%d", &year); ?? ?if (year > 1990) ?? ??? ?printf("输入正确,你要查询的年分是%d年\n", year); ?? ?else ?? ?{ ?? ??? ?printf("输入错误,请重新输入"); ?? ??? ?exit(0); ?? ?} ?? ?printf("月:"); ?? ?scanf("%d", &month); ?? ?if(month>1&&month<13) ?? ??? ?printf("输入正确,你要查询的月分是%d月\n", month); ?? ?else ?? ?{ ?? ??? ?printf("输入错误,请重新输入"); ?? ??? ?exit(0); ?? ?} ?? ?printf("日:"); ?? ?scanf("%d", &day); ?? ? ?? ?if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ?? ?{ ?? ??? ?if (month == 2) ?? ??? ?{ ?? ??? ??? ?if(day<30&&day>0) ?? ??? ??? ?printf("输入正确,你要查询的日子是%d日\n", day); ?? ??? ??? ?else ?? ??? ??? ?{ ?? ??? ??? ?printf("输入错误,请重新输入"); ?? ??? ??? ?exit(0); ?? ??? ??? ?} ?? ??? ?} ?? ??? ?else ?? ??? ??? ?if(day>0&&day<32) ?? ??? ??? ??? ?printf("输入正确,你要查询的日子是%d日\n", day); ?? ??? ??? ?else ?? ??? ??? ?{ ?? ??? ??? ??? ?printf("输入错误,请重新输入"); ?? ??? ??? ??? ?exit(0); ?? ??? ??? ?} ?? ?} ?? ?fish(year, month, day); } void fish(int year, int ?month, int ?day) { ?? ?int i, j; ?? ?int sum = 0;//n-1月的天数; ?? ?int t = 0; ?? ?int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };//为了方便计算,将a[0]省略;这样a[1]代表1月以此类推 ?? ?for (i = 1990; i < year; i++) ?? ?{ ?? ??? ?if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) ?? ??? ??? ?t++;//t代表闰年有几个,也代表多了几天; ?? ?} ?? ?printf("闰年有%d年\n", t); ?? ?year = year - 1990-1;//注意还要减一,来计算天数; ?? ?month = month - 1;//方便计算天数; ?? ?for (i = 0;i <month; i++) ?? ?{ ?? ??? ?sum += a[i+1]; ?? ?} ?? ?sum += day+t+year*365; ?? ?printf("总天数为:%d\n", sum); ?? ?if (sum % 5 == 5 || sum % 5 == 4) ?? ??? ?printf("晒网"); ?? ?else ?? ??? ?printf("打鱼"); }
|