一、问题描述
某人从1990年一月一日开始“三天打鱼两天晒网”,问某天以后是打鱼还是晒网?
二、设计思路
1.输入日期
2.求1990年一月一日到该日期天数
3.对天数求余,根据余数输出“打鱼”或“晒网”
三、程序流程图
四、代码实现
#include <iostream>
using namespace std;
int runYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return 1;
else
return 0;
}
int countDay(int y, int m, int d) {
int perMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int totalDay = 0, year, i;
for (year = 1990; year < y; year++) {
if (runYear(year))
totalDay = totalDay + 366;
else
totalDay = totalDay + 365;
}
if (runYear(y))
perMonth[2]++;
for (i = 1; i < m; i++) {
totalDay += perMonth[i];
}
totalDay += d;
return d;
}
int main() {
int year, month, day;
cin >> year >> month >> day;
int totalDay;
int result;
totalDay = countDay(year, month, day);
result = totalDay % 5;
if (result > 0 && result < 4)
printf("今天打鱼");
else
printf("今天晒网");
}
标签:totalDay,4.16,int,31,30,result,year,打卡,建民
From: https://www.cnblogs.com/cor0000/p/17321220.html