题解 | #计算日期到天数转换#

计算日期到天数转换

http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

#include<iostream>
using namespace std;
int main()
{
    static int array[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    int year,month,day;
    int ret = 0,flag = 0;
    while(cin>>year>>month>>day)
    {
        int i = 1;
        while(i < month)//计算第n-1月的天数
        {
            ret += array[i];
            i++;
        }
            ret += day;//计算第n月的天数
        if(month > 2 && ((year % 4 == 0 && year % 100 != 0 )|| year % 400 == 0))
        {

            ret += 1; //闰年的情况下加1天
        }
         cout<< ret <<endl;
    }



}
全部评论

相关推荐

06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务