计算某日之后,这年所剩余的天数
来源:互联网 发布:js 数组 map方法 编辑:程序博客网 时间:2024/06/06 18:03
#include<iostream>
#include<cstring>
#include"test1.h"
#include"stdio.h"
using std::cout;
using std::cin;
using std::endl;
#define TRUE 1
#define FALSE 0
#define BIGMONTHLENG 7
int bigMonth[BIGMONTHLENG] =
{
1,
3,
5,
7,
8,
10,
12
};
bool bLeapYear = FALSE;
int countDay(int month, int day);
bool findBigMonth(int month);
int main()
{
int year,month,day;
int totall = 0;
year = 0;
month = 0;
day = 0;
cout<<" please input year, month, day\n";
cin >> year;
if(year <1000 || year > 9999)
{
cout<<" year is invalid, please input again.\n";
cin >> year;
}
cin >> month;
if(month <0 || month > 12)
{
cout<<" month is invalid, please input again.\n";
cin >> month;
}
cin >> day;
if(day < 1 || day > 31)
{
cout<<" day is invalid, please input again.\n";
cin >> day;
}
if(year % 100 == 0)
{
if(year % 400 == 0)
bLeapYear = TRUE;
}
else
{
if(year % 4 == 0)
bLeapYear = TRUE;
}
totall = countDay(month, day);
using namespace std;
printf( "year: %d, month: %d, day: %d" , year , month , day);
printf("\n Left %d day int this year.\n", totall);
return 0;
}
int countDay(int month, int day)
{
int totall = 0;
if(month > 12 || month < 0 || day >31 || day < 0 || (month == 2 && day > 29))
{
cout<< "\n\n";
cout<< "parameter is error!!\n";
cout<< "\n\n";
}
int tmpMonth = month;
if(TRUE == findBigMonth(tmpMonth))
{
totall = 31 - day;
}
else
{
if(tmpMonth == 2 && bLeapYear == TRUE)
totall = 29 - day;
else if(tmpMonth == 2)
totall = 28 - day;
else
totall = 30 - day;
}
tmpMonth++;
while(tmpMonth < 13)
{
if(TRUE == findBigMonth(tmpMonth))
{
totall += 31;
}
else
{
if(tmpMonth == 2 && bLeapYear == TRUE)
totall += 29;
else if(tmpMonth == 2)
totall += 28;
else
totall += 30;
}
tmpMonth++;
}
return totall;
}
bool findBigMonth(int month)
{
bool tmp = FALSE;
for(int i = 0; i< BIGMONTHLENG; i++)
{
if(month == bigMonth[i])
{
tmp = TRUE;
break;
}
}
return tmp;
}
#include<cstring>
#include"test1.h"
#include"stdio.h"
using std::cout;
using std::cin;
using std::endl;
#define TRUE 1
#define FALSE 0
#define BIGMONTHLENG 7
int bigMonth[BIGMONTHLENG] =
{
1,
3,
5,
7,
8,
10,
12
};
bool bLeapYear = FALSE;
int countDay(int month, int day);
bool findBigMonth(int month);
int main()
{
int year,month,day;
int totall = 0;
year = 0;
month = 0;
day = 0;
cout<<" please input year, month, day\n";
cin >> year;
if(year <1000 || year > 9999)
{
cout<<" year is invalid, please input again.\n";
cin >> year;
}
cin >> month;
if(month <0 || month > 12)
{
cout<<" month is invalid, please input again.\n";
cin >> month;
}
cin >> day;
if(day < 1 || day > 31)
{
cout<<" day is invalid, please input again.\n";
cin >> day;
}
if(year % 100 == 0)
{
if(year % 400 == 0)
bLeapYear = TRUE;
}
else
{
if(year % 4 == 0)
bLeapYear = TRUE;
}
totall = countDay(month, day);
using namespace std;
printf( "year: %d, month: %d, day: %d" , year , month , day);
printf("\n Left %d day int this year.\n", totall);
return 0;
}
int countDay(int month, int day)
{
int totall = 0;
if(month > 12 || month < 0 || day >31 || day < 0 || (month == 2 && day > 29))
{
cout<< "\n\n";
cout<< "parameter is error!!\n";
cout<< "\n\n";
}
int tmpMonth = month;
if(TRUE == findBigMonth(tmpMonth))
{
totall = 31 - day;
}
else
{
if(tmpMonth == 2 && bLeapYear == TRUE)
totall = 29 - day;
else if(tmpMonth == 2)
totall = 28 - day;
else
totall = 30 - day;
}
tmpMonth++;
while(tmpMonth < 13)
{
if(TRUE == findBigMonth(tmpMonth))
{
totall += 31;
}
else
{
if(tmpMonth == 2 && bLeapYear == TRUE)
totall += 29;
else if(tmpMonth == 2)
totall += 28;
else
totall += 30;
}
tmpMonth++;
}
return totall;
}
bool findBigMonth(int month)
{
bool tmp = FALSE;
for(int i = 0; i< BIGMONTHLENG; i++)
{
if(month == bigMonth[i])
{
tmp = TRUE;
break;
}
}
return tmp;
}
阅读全文
0 0
- 计算某日之后,这年所剩余的天数
- 生日剩余天数计算
- Android 计算某天数之后的日期
- 计算某年、某月、某日和某年、某月、某日之间的天数间隔。要求年、月、日通过键盘输入传递到程序中。
- 计算某日期与当前日期天数
- php计算当前时间到下个月的剩余天数
- php计算当前时间到下个月的剩余天数
- ural1759_计算从公元元年1月1日到某年某月某日的天数
- java 计算生日 剩余天数 (两个日期间隔天数)
- 计算两个日期之间所间隔天数的快速算法
- 简单计算出生至今所经历的天数
- extjs计算两个DateField所间隔的月份(天数)
- extjs计算两个DateField所间隔的月份(天数)
- Date类 计算 日期加天数,日期减天数 之后的 日期 通用算法
- 计算某年某月某日是该年的第几天。
- 计算某日是该年的第几天
- 计算某日是该年的第几天
- 计算某日是该年的第几天
- 前端学习网站
- Android实战简易教程-第六十九枪(自定义控件实现雪花飘落效果)
- 让div父元素的高度随子元素高度的变化而变化!
- Android学习很难? 你缺少的只是一颗平静的心
- 关于java的一些知识
- 计算某日之后,这年所剩余的天数
- Supervisor 安装
- 内存管理
- JavaScript提升日No1
- lnmp简介
- 牛客网互联网秋招模拟笔试编程题第三题
- 栅栏密码--Python解密脚本
- 《鸟哥的linux私房菜:基础学习篇》第3版
- keepalived+lvs