第几天? 2005

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2005
#include <stdio.h>

int main()
{
	int year,dd,mm;
	int sum=0;
	while(scanf("%d/%d/%d",&year,&mm,&dd)!=EOF)
	{
		switch(mm)
		{
		case 1:
			sum=dd;
			break;
		case 2:
			sum=31+dd;
			break;
		case 3:
			sum=31+28+dd;
			break;
		case 4:
			sum=31+28+31+dd;
			break;
		case 5:
			sum=31+28+31+30+dd;
			break;
		case 6:
			sum=31+28+31+30+31+dd;
			break;
		case 7:
			sum=31+28+31+30+31+30+dd;
			break;
		case 8:
			sum=31+28+31+30+31+30+31+dd;
			break;
		case 9:
			sum=31+28+31+30+31+30+31+31+dd;
			break;
		case 10:
			sum=31+28+31+30+31+30+31+31+30+dd;
			break;
		case 11:
			sum=31+28+31+30+31+30+31+31+30+31+dd;
			break;
		case 12:
			sum=31+28+31+30+31+30+31+31+30+31+30+dd;
			break;
        default:
			printf("您输入的月份有误,请重新输入!\n");
		}
		if((mm>2)&&((year%400)==0||(year%4==0&&year%100!=0)))  //能被400整除或者被4整除不能被100整除的是闰年 月份要大于2
		{ 
			sum+=1;
		}
		printf("%d\n",sum);
	}
	
	return 0;
}

  ========================================================

#include <stdio.h>

int main()
{
	int yy,dd,mm,sum;
	int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	while(scanf("%d/%d/%d",&yy,&mm,&dd)!=EOF)
	{
        sum=0;
		for(int i=0;i<mm-1;i++)
		{
			sum+=a[i];	//求前几个月的日子之和
		}
		sum+=dd;	//加上本月的天数
		if(mm>2&&(yy%400==0||(yy%4==0&&yy%100!=0)))
		{
			sum++;
		}
		printf("%d\n",sum);
	}
	return 0;
}

posted @ 2010-12-24 10:28  _cc  阅读(275)  评论(0编辑  收藏  举报