描述如题,输入一个日期,格式如: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;
}