九度1096 日期差值

/********************************* 
 *    日期:2013-1-10 
 *    作者:SJF0115 
 *    题号: 九度1096 
 *    题目:日期差值
 *    来源:http://ac.jobdu.com/problem.php?pid=1096 
 *    结果:AC 
 *    题意: 
 *    总结: 
**********************************/ 
#include <stdio.h>

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,
};

//判断闰年
int leap_year(int year){
	if((year%100 != 0 && year%4 == 0) || (year % 400 == 0)){
		return 1;
	}
	else{
		return 0;
	}
}
//求与0000年0月0日的时间差
int TDay(int date){

	int day1 = 0;
	int year = date / 10000;
	int month =  (date % 10000) / 100;
	int day =  date % 100;

	for(int i = 1;i< year;i++){
		if(leap_year(i)){
			day1 += 366;
		}
		else{
			day1 += 365;
		}
	}

	int isleap_year = leap_year(year);

	for(int j = 1;j < month;j++){
		day1 +=  dayOfMonth[j][isleap_year];
	}
	
	day1 += day;

	return day1;
}
//求绝对值
int fabs(int x){

	return x<0? -x:x;
}
int main()
{
    int date1,date2;
	//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); 
    while(scanf("%d %d",&date1,&date2) != EOF)
    {
		printf("%d\n",fabs(TDay(date1) - TDay(date2)) + 1);
	}
	return 0;
}

你可能感兴趣的:(九度1096 日期差值)