LeapAge
SRM 220 · 2004-11-23 · by Kawigi
Problem Statement
Your friend was born on "leap day" and has always been troubled by the fact that he just turned 24 this year on his 5th birthday. You would like to write him a nice program for his birthday to help him and other leap-day-born people keep track of how many birthdays they've had so far.
You will be given two years as
A leap year is any year that is a multiple of 4, unless it is divisible by 100 and not 400. For example, 1984 was a leap year, but 1900 wasn't, because it was divisible by 100 and not 400. 2000 was a leap year, because it was divisible by both 100 and 400.
Notes
- It is possible that year and born are not actually leap years.
Constraints
- year and born will both be between 1582 and 10000 (1582 is when the Gregorian Calendar started, so there were no leap years before then).
- year will be greater than born.
2004 1980 Returns: 6
This is the case in the first paragraph of the problem statement.
10000 1582 Returns: 2042
This is about as old as you get in this problem. Note that while the Gregorian Calendar (and therefore, leap years) started in 1582, 1582 wasn't a leap year.
2007 1981 Returns: 6
You really don't know why your lying friend asked you to write this...
1981 1980 Returns: 0
1984 1983 Returns: 1
Submissions are judged against all 52 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LeapAge with a public method int getAge(int year, int born) · 52 test cases · 2 s / 256 MB per case