天天看點

fjnu 1285 Leap Years

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      
KEY:leap的看能不能被400整除,能不是被4且不能被100整除;      
fjnu 1285 Leap Years
Source:#include < iostream >
fjnu 1285 Leap Years
using   namespace  std;
fjnu 1285 Leap Years
fjnu 1285 Leap Years
int  Y;
fjnu 1285 Leap Years
fjnu 1285 Leap Years
int  Leap()
fjnu 1285 Leap Years
fjnu 1285 Leap Years
... {
fjnu 1285 Leap Years
    if(Y%400==0) return 1;
fjnu 1285 Leap Years
    if(Y%4==0 && Y%100!=0) return 1;
fjnu 1285 Leap Years
    return 0;
fjnu 1285 Leap Years
}
fjnu 1285 Leap Years
fjnu 1285 Leap Years
int  main()
fjnu 1285 Leap Years
fjnu 1285 Leap Years
... {
fjnu 1285 Leap Years
    cin>>Y;
fjnu 1285 Leap Years
    while(Y!=0)
fjnu 1285 Leap Years
fjnu 1285 Leap Years
    ...{    
fjnu 1285 Leap Years
        if(Leap()) cout<<"yes"<<endl;
fjnu 1285 Leap Years
        else cout<<"no"<<endl;
fjnu 1285 Leap Years
        cin>>Y;
fjnu 1285 Leap Years
    }
fjnu 1285 Leap Years
}
fjnu 1285 Leap Years
fjnu 1285 Leap Years

繼續閱讀