#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct month
{
char name [10] ;
char abbrev[4] ;
int days;
int monumb;
};
struct month months[12] =
{
{ "January", "jan", 31,1},
{ "February", "feb", 28,2 },
{ "March", "mar", 31, 3 },
{ "April" ,"apr", 30,4 },
{ "May", "may", 31, 5 },
{ "June", "jun", 30, 6 },
{ "July", "jul", 31,7 },
{ "August","aug", 31, 8 },
{ "September", "sep", 30,9 },
{ "October", "oct", 31, 10 },
{ "November", "nov", 30, 11 },
{ "December", "dec", 31, 12 }
};
int count_days(struct month months[]);
int main(void)
{
int count=0;
puts("Enter year month day(月份可以是月份号、月份名或月份名缩写。) :");
count = count_days(months);
printf("%d天\n", count);
return 0;
}
int count_days(struct month months[])
{
int i,count=0;
int year;
char mont[12];
int mond;
int day;
scanf("%d %s %d",&year,mont,&day);
printf("这是%d年的第", year);
if(isalnum(mont[0]))
{
if(strlen(mont)==2)
mond=(mont[0]-'0')*10+(mont[1]-'0');
else
mond=(mont[0]-'0');
}
else
{
mont[3]='\0';
for(i = 0; i < 3; i++)
mont[i]=tolower(mont[i]);
}
for (i = 0; i < 12; i++)
{
count += months[i].days;
if (strcmp(months[i].abbrev, mont) == 0||mond==months[i].monumb)
return count-(months[i].days-day);
}
return 0;
}