Leap Years

来源:互联网 发布:linux中wget命令 编辑:程序博客网 时间:2024/05/22 06:24

FJNU.1285

Description
Leap days are added to compensate for the tropical year of the earth being slightly longer than 365 days. Years in which these leap days are added have, naturally, been called leap years, which were first introduced in the Julian calendar in 46 BC. The intent was that every fourth year would be a leap year. However, there was a screwup early on causing leap years to (incorrectly) be added every three years (hence 42 BC, 39 BC, etc were all leap years). This was corrected by skipping a few leap years (4 AD is *not* a leap year despite what cal says).
Unfortunately, this compensation still isn't quite right as it over compensates. The Gregorian calendar fixed this (by the way; the switchover from Julian to Gregorian created some interesting calendars, which we won't get into here, but check out Sept. 1752 in cal sometime). The fix was to declare that every year divisible by 100 is *not* a leap year. Unfortunately (again) the fix to the fix isn't quite right. The fix to the fix to the fix is that years divisible by 100 are not leap years, except if the year is divisible by 400 in which case it is. As far as I know there is not a fix to the fix to the fix to the fix to compensate for any remaining inaccuracies.
In this problem, you'll be given a year and asked to determine if it is a leap year. For our purposes all years divisible by 4 and not by 100 are leap years. Any year divisible by 100 and by 400 are also leap years. Anything else is not a leap year.

Input
The input consists of various years. The smallest year will be 1800 to avoid the ugliness of Gregorian calendar switchover and the early mess ups in calculating the leap years. The largest value will 2 billion (despite the end of the 13th Baktun in the Mayan calendar in 2012, which prophesies the end of the fourth and final age). Input is terminated by a 0, which, obviously, should not be processed.

Output
For each year, print out `yes' if it is a leap year and `no' if it isn't.

Sample Input
2012
2000
1900
0

Sample Output
yes
yes
no

Source
udel - fall 2003

My Program

#include<stdio.h>
int leap(int year)
{
  
if(year%100==0)
    
if(year%400==0return 1;
    
else return 0;
  
else if(year%4==0return 1;
         
else return 0;
}

main()
{
  
int year[500],i,n=0,temp;
  scanf(
"%d",&year[0]);
  
while(year[n]!=0)
      scanf(
"%d",&year[++n]);
  
for(i=0;i<n;i++)
    
{
      temp
=leap(year[i]);
      
if(temp==1) printf("yes ");
      
else printf("no ");
    }

}

YOYO's Note:
判断闰年!为数不多的我刚学C时写的程序 = = 还用了子函数呢…… 又开了500的数组……