一个渔夫从2011年1月1日开始每3天打一次鱼,每两天晒一次网,实现输入2011年1月1日以后的任意一天,输出该渔夫是在打渔还是晒网
#include <stdio.h> int main(void) { int year,month,day,result,temp; scanf("%d-%d-%d",&year,&month,&day); result = get_day(year,month,day); if(result == -1){ printf("date err"); } else { temp = result%5; if(temp >3){ printf("feshing"); } else { printf("sleep"); } } return 0; } int is_lead(int year) { if((year%4==0 && year%100 !=0) || year %400 == 0) return 1; return 0; } int get_day(int year, int month, int day) { int month_data[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; int month_data_lead[12] = {31,29,31,30,31,30,31,31,30,31,30,31}; int *month_pointer; int start_year = 2011; int start_month = 1; int start_day = 1; int count = 0; int i; if(is_lead(year)){ month_pointer = month_data_lead; } else { month_pointer = month_data; } if(year < start_year) return -1; if(year == start_year && month == start_month && day == start_day) return 1; count += day; for(i=1;i<month;i++) { count += month_pointer[i]; } for(i=start_year;i<year;i++) { if(is_lead(i)){ count += 366; } else { count += 365; } } return count; } int is_lead(int year) { if((year%4==0 && year%100 !=0) || year %400 == 0) return 1; return 0; }