计算日子差。自由年月日。含闰年判断
2016-02-23 19:47
435 查看
// main.cpp
// 打鱼晒网问题
//
// Created by Angel on 16/1/27.
//
// 打鱼晒网问题
//
// Created by Angel on 16/1/27.
//
#include #include using namespace std; //function //是否为闰年 long int judgement1(int); //是否为大月 long int judgement2(int,bool); //计算日子 int judgement3(int); //闰年 bool lunar(int); //计算 void display(long int); #define YEAR 1993 #define MONTH 6 #define DAY 9
int main() { int year,month,day; long int count[3]; bool t; long int total; cout<<"Count the date from"<<YEAR<<'/'<<MONTH<<'/'<<DAY<<"to the date you want."<<endl; cout<<"【EOF】to quit."<<endl; while(cin.get()!=EOF){ cout<<"Year: "<<endl; cin>>year; count[0]=judgement1(year); t=lunar(year); cout<<"Month: "<<endl; cin>>month; count[1]=judgement2(month,t); cout<<"Day: "<<endl; cin>>day; count[2]=day; //多余的日子 total=count[0]+count[1]+count[2]-judgement2(MONTH,lunar(YEAR))-(DAY-1); cout<<"Total: "<<total<<endl; cout<<"计算这一天是在打渔还是筛网:"<<endl; display(total); cin.clear(); cin.get(); } }
//计算年份 long int judgement1(int a){ a=a-YEAR; long int ye=0; for(int i=0;i if(lunar(YEAR+i)) ye=ye+366; else ye=ye+365; return ye; }
//判断闰年 bool lunar(int yea){ if( yea%4 == 0){ if( yea0 == 0){ if( yea@0 ==0) return true; else return false; } else return true; } else return false; }
//计算月份 long int judgement2(int a,bool t){ int day=0; int b=31,s=30; switch(a){ case 12: day=day+s; case 11: day=day+b; case 10: day=day+s; case 9: day=day+b; case 8: day+=b; case 7: day+=s; case 6: day+=b; case 5: day+=s; case 4: day+=b; case 3: if(t) day+=29; else day+=28; case 2: day+=b; case 1: day+=0;break; default: cout<<"WRONG.";break; } return day; }
//展示晒网打渔 void display(long int a){ a=a%5; switch(a){ case 0: case 4: cout<<"晒网"<<endl;break; case 2: case 3: case 1: cout<<"打渔"<<endl;break; }return; }
相关文章推荐
- 建立企业信息化-重头开始
- C#实现线程安全的简易日志记录方法
- JS基于cookie实现来宾统计记录访客信息的方法
- 用VBS记录客户机操作的代码
- 从数据库中读取记录横向排列
- C++键盘记录程序代码
- PHP判断数据库中的记录是否存在的方法
- javascript 实现 秒杀,团购 倒计时展示的记录 分享
- MySQL生产库Insert了2次同样的记录但是主键ID是不一样的问题的分析过程
- linux中 shell 历史命令记录功能
- php浏览历史记录的方法
- Golang记录、计算函数执行耗时、运行时间的一个简单方法
- FileMaker 14学习笔记整理
- 关于awk与其它命令一起使用显示文本信息
- SQL Server 2008安装图解及遇到的问题记录
- Linux/unix 键盘记录 ixkeylog
- Linux键盘记录sh2log keylogger notes
- linux删除两个文档中相同记录的行
- day1 python学习随笔
- mysql Table ‘****‘ is marked as crashed and should be repaired错误解决。