Statistics

Problem Statement for "LazyYear"

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

  8. 22900

    Returns: 4

  9. 987654321

    Returns: 22345679

  10. 22904

    Returns: 0

  11. 231000000

    Returns: 79000000

  12. 932000000

    Returns: 78000000

  13. 832000000

    Returns: 78000000

  14. 1999

    Returns: 0

  15. 999

    Returns: 101

  16. 12345

    Returns: 0

  17. 54321

    Returns: 6679

  18. 999999

    Returns: 10001

  19. 2291996

    Returns: 0

  20. 987123454

    Returns: 22876546

  21. 987898940

    Returns: 22101060

  22. 7645321

    Returns: 454679

  23. 2312656

    Returns: 787344

  24. 200000000

    Returns: 10000000

  25. 931217206

    Returns: 78782794

  26. 876543211

    Returns: 33456789

  27. 487654321

    Returns: 22345679

  28. 23126534

    Returns: 7873466

  29. 132000000

    Returns: 78000000

  30. 2293897

    Returns: 7

  31. 2050

    Returns: 50

  32. 230000000

    Returns: 80000000

  33. 987654323

    Returns: 22345677

  34. 2001

    Returns: 99

  35. 2290000

    Returns: 0

  36. 987654531

    Returns: 22345469

  37. 2290100

    Returns: 4


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: