#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;放在预处理代码的后面