九度1186 打印日期

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

int dayOfMonth[13][2] = 
{
	0,0,
    31,31,
	59,60,
	90,91,
	120,121,
    151,152,
	181,182,
	212,213,
	243,244,
	273,274,
	304,305,
	334,335,
	365,366,
};

//判断闰年
int leap_year(int year){
	if((year%100 != 0 && year%4 == 0) || (year % 400 == 0)){
		return 1;
	}
	else{
		return 0;
	}
}
//计算哪月哪天
void TDay(int days,int year){

	int i;
	int isleap_year = leap_year(year);

	for(i = 1;i < 13;i++){
		if(days <= dayOfMonth[i][isleap_year]){
			break;
		}
	}
	
	int day = days - dayOfMonth[i-1][isleap_year];

	printf("%04d-%02d-%02d\n",year,i,day);
}

int main()
{
    int day,year;
	//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); 
    while(scanf("%d %d",&year,&day) != EOF)
    {
		TDay(day,year);
	}
	return 0;
}

你可能感兴趣的:(九度1186 打印日期)