NYOJ 75 日期的计算(打表 日期类水题)

描述如题,输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第几天。
输入
第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每行的输入数据都是一个按题目要求格式输入的日期。
输出
每组输入数据的输出占一行,输出判断出的天数n
样例输入
3
2000 4 5
2001 5 4
2010 10 24
样例输出
96
124
297

虽然很简单,还是套模板做了,因为打表吧,运行时间略长,但通过还是没有问题的。

#include <cstdio>
#define ISYEAP(x) x%100!=0&&x%4==0||x%400==0?1:0
int dayOfMonth[13][2]={
    0,0,
    31,31,
    28,29,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31
};
struct date
{
    int year;
    int month;
    int day;
    void nextDay()
    {
        day++;
        if(day>dayOfMonth[month][ISYEAP(year)])
        {
            month++;
            day=1;
            if(month>12)
            {
                year++;
                month=1;
            }
        }
    }
};
int inf[5001][13][32];
int main()
{
    date nor;
    int x=0;
    nor.year=0;
    nor.month=1;
    nor.day=1;
    while(nor.year!=5001)
    {
        inf[nor.year][nor.month][nor.day]=x;
        x++;
        nor.nextDay();

    }
    int n;
    int year;
    int month;
    int day;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d%d%d",&year,&month,&day);
        printf("%d\n",inf[year][month][day]-inf[year][1][1]+1);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值