文章

34

粉丝

261

获赞

10

访问

10.8k

头像
日期差值 题解:通过获取当年天数来计算
fzh VIP
P1290 上海交通大学/西北工业大学2019机试
发布于2024年2月7日 14:40
阅读数 389

#include<bits/stdc++.h>
using namespace std;

//用于判断是不是闰年

int Judge(int x)
{
    if (x % 400 == 0 || (x % 100 != 0 && x % 4 == 0)) return 1;
    return 0;
}
//计算当前日期在当年一共有多少天
int GetDay(int x)
{
    int year, month, day, result;
    result = 0;
    year = x / 10000;
    day = x % 100;
    month = (x % 10000 - day) / 100;
    for (int i = 1; i < month; i++)
    {
        if (i == 2)
        {
            if (Judge(year)) result += 29;
            else result += 28;
        }

        else if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) result += 31;
     &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发