三天打鱼两天晒网

打鱼的人要饿死了
别说了,第一次写这东西。。。。
有点难受
下面的是主要的函数

#include"head.h"
using namespace std;
int fish1(time a) {
 if (a.month >= 1 && a.month <= 12 && a.day >= 1 && a.day <= 31)//判断年月日输入是否有问题
  ;
 else {
  return 0;
 }
 if (a.year % 4 == 0 && a.month == 2 && a.day > 29) {//判断闰年时间是否有问题
  return 0;
 }
 if (a.year % 4 != 0 && a.month ==2 && a.day >= 29) {//判断非闰年时间是否有问题
  return 0;
 }
 //补丁////
 if(a.year%4!=0)//检查是否月的天数有问题
  if (a.day > shijian[0][a.month - 1])
   return 0;
 /////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////
 if (a.year < 2012 || (a.year == 2012 && a.month < 3)) {//时间处于2012.3.1之前,没有闰年的干扰
  int b = 365 * (a.year - 2010);
  int c = 0;//累加月的日数的变量
  for (int i = 1; i < a.month; i++) {//累加月的天数
   c += shijian[0][i - 1];
  }
  return(b + c + a.day);
 }
 if (a.year > 2012 || (a.year == 2012 && a.month >= 3)){ //存在2.29这个特殊时间
  int b = a.year - 2012;
  if (a.month >= 3) {
   int c = 1461 * (b / 4);//年的日子累加
   int d = 0;
   for (int i = 3; i < a.month; i++) {
    d += shijian[1][i - 1];
   }
   return(c + d + a.day+790);
  }
 }
 return 0;
}

这是主函数入口

//author
//time--2019.2.27
//location
//17408070829
#include "head.h"
using namespace std;
int main() {
 int fish1(time);//计算时间的函数声明
 time time1;//声明结构体变量
 //初始化结构体变量
 cout << "输入年(时间需要大于2010.1.1)" << endl;
 cin >> time1.year;
 cout << "输入月" << endl;
 cin >> time1.month;
 cout << "输入日" << endl;
 cin >> time1.day;
 int Time = fish1(time1);
 if (!Time) {//判断输入是否有问题
  cout << "你的输入有问题,请检查" << endl;
  getchar();
  getchar();
  return 0;
 }
 //cout << Time << endl;
 if (Time % 5 <= 3&&Time%5!=0)
  cout << "这天打鱼" << endl;
 else
  cout << "这天晒网" << endl;
 getchar();
 getchar();
 return 0;
 
}

新手不要介意

#include<iostream>
#include<fstream>//作为文件功能,待开发
using namespace std;
struct time{
 int year;
 int month;
 int day;
};
static int shijian[2][12] = { 31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31 };//分别为非闰年和闰年的每个月的天数

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值