c语言(两天打鱼,三天晒网)
来源:互联网 发布:捕鱼游戏源码搭建教程 编辑:程序博客网 时间:2024/04/20 07:14
#include<stdio.h>
typedef struct date {
int year;
int month;
int day;
}DATE;
int countday(DATE from, DATE to);
int isLeap(int year);
int main()
{
DATE end, start;
int totaldays;
int result;
printf("请输入开始日期\n");
scanf("%d%d%d", &start.year, &start.month, &start.day);
printf("请输入结束日期\n");
scanf("%d%d%d", &end.year, &end.month, &end.day);
totaldays = countday(start, end);
result = totaldays % 5;
if(result > 0 && result < 4)
puts("今天打鱼");
else
puts("今天晒网");
return 0;
}
int isLeap(int year)
{
if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return 1;
return 0;
}
int countday(DATE from, DATE to)
{
int perMonth[13]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int result = 0, i;
if (isLeap(from.year))
perMonth[2] = 29;
int t = 12;
if (from.year == to.year) //同一年
t = to.month - 1;
for(i = from.month; i <= t; i++) { //开始的那年的月份直接加到12月
result += perMonth[i];
}
result -= from.day;
perMonth[2] = 28;
result += 366;
else
result += 365;
}
if(isLeap(to.year))
perMonth[2] = 29;
if (from.year != to.year)
for(i = 1; i <= to.month - 1; i++) { //把终点月-1加上,不算当月
result += perMonth[i];
}
result += to.day;//将当月多的几天算进去
return result;
}
typedef struct date {
int year;
int month;
int day;
}DATE;
int countday(DATE from, DATE to);
int isLeap(int year);
int main()
{
DATE end, start;
int totaldays;
int result;
printf("请输入开始日期\n");
scanf("%d%d%d", &start.year, &start.month, &start.day);
printf("请输入结束日期\n");
scanf("%d%d%d", &end.year, &end.month, &end.day);
totaldays = countday(start, end);
result = totaldays % 5;
if(result > 0 && result < 4)
puts("今天打鱼");
else
puts("今天晒网");
return 0;
}
int isLeap(int year)
{
if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return 1;
return 0;
}
int countday(DATE from, DATE to)
{
int perMonth[13]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int result = 0, i;
if (isLeap(from.year))
perMonth[2] = 29;
int t = 12;
if (from.year == to.year) //同一年
t = to.month - 1;
for(i = from.month; i <= t; i++) { //开始的那年的月份直接加到12月
result += perMonth[i];
}
result -= from.day;
perMonth[2] = 28;
for (i = from.year + 1; i <= to.year - 1; i++) //判断中间间隔年的润平
{
if (isLeap(i))result += 366;
else
result += 365;
}
if(isLeap(to.year))
perMonth[2] = 29;
if (from.year != to.year)
for(i = 1; i <= to.month - 1; i++) { //把终点月-1加上,不算当月
result += perMonth[i];
}
result += to.day;//将当月多的几天算进去
return result;
}
0 0
- c语言(两天打鱼,三天晒网)
- 打鱼还是晒网C语言
- 打鱼晒网C实例
- c解决打鱼晒网问题
- 打鱼还是晒网
- 打鱼还是晒网
- 打鱼晒网问题
- 打鱼还是晒网
- 打鱼还是晒网
- 打鱼还是晒网
- 打鱼还是晒网
- 打鱼晒网
- 打鱼还是晒网
- 打鱼晒网
- 打鱼还是晒网问题
- 打鱼还是晒网问题
- 2811:打鱼还是晒网
- 打鱼还是晒网C++
- warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s inste
- 嵌套盒子,让子div在父div中居中
- 关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
- 使用资源文件配置 Spring数据库连接
- readResolve()方法与串行化
- c语言(两天打鱼,三天晒网)
- c++primerP29-----P51 基本内置类型,变量,复合类型
- 前端框架Vue.js的使用及具体页面跳转时的参数传递
- Python迭代器和生成器
- Filter过滤器(vue.js)
- 网络编程中的超时检测
- 不用第三方变量如何交换两个数的值
- MySQL中的触发器
- 视图学习之建立视图、授权、同义词创建