Description
你知道,2012-1-1是该年的第1天,而9999-9-9呢?给你一个具体的日期,计算该日期是该年的第几天。
Input
输入一个日期,格式为:Year-month-day。year是小于9999的正整数。
Output
一个整数,表示该日期是该年的第几天。
Sample Input
2012-3-1
Sample Output
61
HINT
Source
#include<stdio.h>
int getsumday(int year,int mouth,int day);//计算天数的函数
int isleap(int year);//判断闰年
void main ()
{
int year,mouth,day;
scanf("%d-%d-%d",&year,&mouth,&day);
printf("%d\n",getsumday(year,mouth,day));
}
int isleap(int year)
{ //若为真返回1是闰年,返回0为平年
return ( ( year%400==0 ||year%4==0 && year%100!=0 ) );
}
int getsumday(int year,int mouth,int day)
{
int k,leap=0;
int tab[2][13] =
{
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};//闰年
//判断闰年
leap = isleap(year);
for(k=1;k<mouth;k++)
{
day=day+tab[leap][k];
}
return day;
}
#include <stdio.h>
int main()
{
int a[13]={0};
int year, month, day, sumday=0, i, k=0;
scanf("%d%d%d",&year, &month, &day);
if(year%400==0 || year%4==0 && year%100!=0)
k = 1;
for(i=1;i<=12;i++)
{
if(i==4||i==6||i==9||i==11)
a[i] = 30;
else if(i==2)
a[i] = 28;
else
a[i] = 31;
}
sumday=0;
if (k==1&&month>2)
{
for(i=1; i<month; i++)
sumday += a[i];
sumday+=day+1;
}
else
{
for(i=1; i<month; i++)
sumday+=a[i];
sumday+=day;
}
printf("%d",sumday);
}
#include<stdio.h>
int leap(int year);
void main ()
{
int year;
scanf("%d",&year);
printf("%d",leap(year));
}
int leap(int year)
{ //闰年二月29天,闰年返回1,平年返回0
return ( ( year%400==0 ||year%4==0 && year%100!=0 ) );
}