#include
int dayCountArray[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct Date{
int year, month, day;
};
int IsLeapYear(struct Date date){
if (0==date.year%400 || (0!= date.year%100 && 0==date.year%4)) {
return 1;
}
return 0;
}
int Dayth(struct Date date){
int sum = 0;
for (int i = 1; i < date.month; ++i) {
sum += dayCountArray[i];
}
sum += date.day;
if (!IsLeapYear(date) && date.month>2) {
--sum;
}
return sum;
}
int Judge(struct Date date){
if (date.year<0
|| date.month < 1 || date.month > 12
|| date.day < 0
|| date.day > dayCountArray[date.month]
|| (2==date.month && !IsLeapYear(date) && date.day > 28)) {
return 0;
}
return 1;
}
int main(int argc, const char * argv[]) {
struct Date date;
for (int i = 0; i < 10; ++i) {
printf("please input date!\n");
scanf("%d %d %d", &date.year, &date.month, &date.day);
if (Judge(date)) {
printf("dayth : %d\n", Dayth(date));
}else{
printf("Error input!\n");
}
}
return 0;
}