#include <stdio.h>

//this function is to determine whether the year is a leap yeapr or not
int leapyear(int year){

	if ((year % 400 == 0) || ((year % 4 == 0) && !(year % 100 == 0)))
		return 1;
	else 
		return 0;
}

int main(){

	int monthday[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
	int year = 0;
	int month = 0;
	int day = 0;
	int i = 1,j = 1;
	int result = 0;
	
	printf("please input the year:");
	scanf("%d",&year);
	
	printf("please input the month:");
	scanf("%d",&month);
    while( month < 1 || month > 12 ){
		printf("Invalid month!! FUCK!\n");
		printf("please input the month:");
	    scanf("%d",&month);		
	}
    
	printf("please input the date:");
	scanf("%d",&day);
    if (!leapyear(year)){
		while (day < 1 || day > monthday[month]){
			printf("Invalid date!! FUCK!\n");
			printf("please input the date:");
	        scanf("%d",&day);
        }
	}
    
	while (month == 2 && (day > 29 || day < 1)){
		printf("Invalid date!! FUCK!\n");
		printf("please input the date:");
	    scanf("%d",&day);
	}
	
	for(i=1;i<month;i++){
		result = result + monthday[i];
    }

    result = result + day;

	if( (month > 2) && leapyear(year) )
		result++;

	printf("%d年%d月%d日是一年中的第%d天",year,month,day,result);
	
	return 0;

}


