-
题目描述:
-
输入年、月、日,计算该天是本年的第几天。
-
输入:
-
包括三个整数年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。
-
输出:
-
输入可能有多组测试数据,对于每一组测试数据,输出一个整数,代表Input中的年、月、日对应本年的第几天。
-
样例输入:
-
1990 9 20 2000 5 1
-
样例输出:
-
263 122
-
答疑:
- 解题遇到问题?分享解题心得?讨论本题请访问: http://t.jobdu.com/thread-7794-1-1.html
#include <iostream>
#include <cstdio>
#define isLeapYear(x) (x%4==0&&x%100!=0)||x%400==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
};//非闰年存在[0],闰年存在[1]
struct Date{
int year;
int month;
int day;
void nextDay(){
day++;
if (day>dayOfMonth[month][isLeapYear(year)]){
day=1;
month++;
if (month>12){
month=1;
year++;
}
}
}
};
int abs(int x){
return x>0?x:-x;
}
int main (){
//initiate
Date dateTest;
dateTest.year=1;
dateTest.month=1;
dateTest.day=1;
int cnt=0;
//preprocess
while (dateTest.year<10000){
buf[dateTest.year][dateTest.month][dateTest.day]=cnt;
dateTest.nextDay();
cnt++;
}
//body
return true;
}