九度oj 今年的第几天(一个预处理带来的麻烦)

#include <iostream>
#include <stdio.h>
#define ISYEAP(x) x%400==0||(x%100!=0&&x%4==0)
using namespace std;
int buf[10000][13][32];
int DayofMonth[13][2]=
{
    0,0,
    31,31,//1
    28,29,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31,//7
    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)])
        {
            day=1;
            month++;
            if(month>12)
            {
                month=1;
                year++;
            }
        }
    }
};
int main()
{
    Date datetest;
    datetest.year=0;
    datetest.month=1;
    datetest.day=1;
    int cns=0;
    while(datetest.year<=2500)
    {
        buf[datetest.year][datetest.month][datetest.day]=cns;
        datetest.nextDay();
        cns++;
    }
    int days,nian,yue,ri;
    while(scanf("%d%d%d",&nian,&yue,&ri)!=EOF)
    {
        days=buf[nian][yue][ri]-buf[nian][1][1]+1;
       // days=buf[nian][yue][ri];
        cout<<days<<endl;
    }
    return 0;
}
先贴一下正确代码下面是超时代码

#include <iostream>
#include <stdio.h>
#define ISYEAP(x) x%400==0||(x%100!=0&&x%4==0)
using namespace std;
int buf[2500][13][32];
int DayofMonth[13][2]=
{
    0,0,
    31,31,//1
    28,29,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31,//7
    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)])
        {
            day=1;
            month++;
            if(month>12)
            {
                month=1;
                year++;
            }
        }
    }
};
int main()
{
    int days;
    int nian,yue,ri;
    Date date;
    date.year=0;
    date.month=1;
    date.day=1;
    int cns=0;
    while(date.year<=2500)
    {
        buf[date.year][date.month][date.day]=cns;
        date.nextDay();
        cns++;
    }
    while(scanf("%d%d%d",&nian,&yue,&ri)!=EOF)
    {
        days=buf[nian][yue][ri]-buf[nian][1][1]+1;
       // days=buf[nian][yue][ri];
        cout<<days<<endl;
    }
    return 0;
}
因为涉及到预处理 必须把 int days;
    int nian,yue,ri;放在预处理代码的后面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值