【ACM】杭电OJ 2005

 题目链接:杭电OJ 2005

第一次写的时候:

#include "stdio.h"
int main ()
{
	int year,month,day,days,flag;
	while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
	{
		if((year%4==0 && year%100!=0)||(year%400==0))
		{
			flag=1;
		}
		else
		{
			flag=0;
		}
		days=0;
		switch(month)
		{
			case 1:
			{
				days+=day;break;
			} 
			case 2:
			{
				days+=(day+31);break;
			}
			case 3:
			{
				days+=(day+31+28);
				if(flag==1)
				{
					days+=1;
				}break;
			}
			case 4:
			{
				days+=(day+31+28+31);
				if(flag==1)
				{
					days+=1;
				}break;				
			} 
			case 5:
			{
				days+=(day+31+28+31+30);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
			case 6:
			{
				days+=(day+31+28+31+30+31);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
			case 7:
			{
				days+=(day+31+28+31+30+31+30);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
			case 8:
			{
				days+=(day+31+28+31+30+31+30+31);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
			case 9:
			{
				days+=(day+31+28+31+30+31+30+31+31);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
			case 10:
			{
				days+=(day+31+28+31+30+31+30+31+31+30);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
			case 11:
			{
				days+=(day+31+28+31+30+31+30+31+31+30+31);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
			case 12:
			{
				days+=(day+31+28+31+30+31+30+31+31+30+31+30);
				if(flag==1)
				{
					days+=1;
				}break;				
			}
		}
		printf("%d\n",days);
	}
	return 0;
}

改进以后:

#include "stdio.h"
int main ()
{
	int year,month,day,days,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
	{
		days=0;
		for(int i=1;i

上面一行是最新提交的

你可能感兴趣的:(ACM)