日期倒计时

日期倒计时

题目描述

在经济、科技日益发达的今天,人们对时间的把握越来越严格,对于一个一定影响力的公司的高管来说,他可能要将自己的行程提前安排到下个月。对于普通人来说,他也可能将几天之后的安排已经提前做好。

请设计一个程序计算出今天距离未来的某一天还剩多少天。

假设今天是2015年10月18日。

输入

输入一个日期格式为yyyy-MM-dd,不考虑日期是否小于今天。

样例输入

2015-10-19

输出

输出一个数字表示今天(2015年10月18日)距离该日期还剩多少天。

样例输出

1

时间限制 C/C++语言:1000MS 其它语言:3000MS
内存限制 C/C++语言:65536KB 其它语言:589824KB
#include<iostream>
#include<cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <ctype.h>
using namespace std;
#include<iostream>
using namespace std;


int monthList[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};




bool isLeapYear(int year)
{
  return ((year%100)&&!(year%4))||!(year%400);
}


int getLeftDates(int year, int month, int date)
{
    int dateCount = 0;
    for(int i = 2015; i < year; i++)
    {
        if(isLeapYear(i)) dateCount += 366;
        else dateCount += 365;
    }


    for(int i = 1; i <= month; i++)
    {
        if(isLeapYear(year) && i == 2) dateCount += 29;
        else dateCount += monthList[i - 1];
    }


    dateCount += date;
    return dateCount;


}


int main()
{
    int year, month, date;
    char c;
    cin >> year >> c >> month >> c >> date;


    int leftDatesStart = getLeftDates(2015, 10, 18);
    int leftNowDates = getLeftDates(year, month, date);


    int leftDates = leftNowDates - leftDatesStart;


    cout << leftDates << endl;




    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值