TopcoderArchiveVisit Topcoder
SRM10 Sep 2002
SRM 113

LazyYear

Problem statement, definition, constraints, and public examples.

Problem Statement

Some dates can be written by simply inserting two slashes into the 4 digit year. For example January 9th, 1999 can be written by first writing the year, "1 9 9 9", and then just inserting two slashes to obtain the date "1/9/99". It has been decided that any year which can be written as a date by inserting two slashes should be designated as a Lazy Year. Clearly, every year from 1900 to 1999 was a Lazy Year, but the next Lazy Year after 1999 is 101 years later in year 2100. On February 1st, 2100, the date is "2/1/00".

The date is always written as "<month>/<day>/<year>" (quotes and angle brackets for clarity) where:

  • <month> is from 1-12 inclusive (no leading zeros)
  • <day> is from 1 to n inclusive where n is the number of days in month <month>. (no leading zeros)
  • <year> is always at least two digits and the digits of <year> are the same as the final digits of the actual year. For example, 2/23/565 must match some year where the last 3 digits are 565. The year 223565 is a Lazy Year.
  • <month> and <day> combined must be at least 3 digits long unless the entire year is only four digits long. In other words, It is ok to have a lazy year in 1999 using 1/9/99 because 1999 only has four digits. It is NOT ok to have 1/9/999 because 19999 does not have four digits.

Write a method nextTime that takes as argument an int representing the current year. Return 0 if the current year is a Lazy Year. Otherwise, return the number of years before the next Lazy Year.

Definition

Class:
LazyYear
Method:
nextTime
Parameters:
int
Returns:
int
Method signature:
int nextTime(int year)
(be sure your method is public)

Notes

  • A Lazy Year is any year where there is at least one day when the date can be written by simply inserting two slashes somewhere in the year.
  • The number of days in each of the twelve months are (on a non-leap year):{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
  • During a leap year, there are 29 days in the 2nd month instead of 28. A leap year occurs if all of the following are true:-The year is divisible by 4-The year is not divisible by 100 unless the year is also divisible by 400.
  • For example, 1700 and 1900 are not leap years, but 2400 is a leap year.

Constraints

  • year must be between 1 and 1000000000, inclusive.

Examples

  1. 1999
    Returns: 0
    We know from the problem statement that 1999 is a Lazy Year: "1/9/99".
  2. 999
    Returns: 101
    There are no Lazy Years until 1100. January 1st, 1100, is just "1/1/00".
  3. 22900
    Returns: 4
    22900 is not a Lazy Year because there are only 28 days in the 2nd month of a normal year. Therefore, we will not have the day 2/29/00. The next Lazy Year is actually on 22904, because 22904 happens to be a leap year!
  4. 12345
    Returns: 0
    In this case, the date can be 1/23/45.
  5. 54321
    Returns: 6679
    The next lazy year is 61000, when the date is 6/10/00.
  6. 999999
    Returns: 10001
  7. 987654321
    Returns: 22345679
Back to all problems