您的位置:首页 > 其它

ACM-2005

2016-04-14 19:02 375 查看
Problem Description

给定一个日期,输出这个日期是该年的第几天。

Input

输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。

Output

对于每组输入数据,输出一行,表示该日期是该年的第几天。

Sample Input

1985/1/20
2006/3/12


Sample Output

20
71

#include<stdio.h>
#include<math.h>

int isleapyear(int y)
{
if(((y%4==0) && (y%100!=0))||(y%400==0))
{
return 1;
}
else
{
return 0;
}
}

int main()
{
int year,month,day;
char l,m;
int y[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
while(scanf("%d%c%d%c%d",&year,&l,&month,&m,&day)!=EOF)
{
int i,j,n=0;
i=isleapyear(year);
for(j=0; j<month-1;j++)
{
n+= y[i][j];
}
n+=day;
printf("%d\n",n);
n=0;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: