TopcoderArchive
SRM8 Sep 2003
SRM 163

CalendarRecycle

Problem statement, definition, constraints, and public examples.

Problem Statement

Jane is visiting your cubicle when she spies the Elvis calendar hanging on your wall.

"That's not right, is it?" she asks rhetorically.

Your Elvis calendar says that September 8 is a Sunday, but it's actually a Monday. Elvis Presley, the King of Rock 'n' Roll, is no liar. It's just that you bought the calendar last year. This is a 2002 calendar, whereas the current year is 2003. The dates no longer match the days of the week! But there will come a year when every date falls on the same day of the week as in 2002, and the King will reign again.

Given an int representing a year between 2002 and 9999, return the closest future year with which it shares a calendar. Jane reminds you that there are 30 days in April, June, September, and November. The remaining months, with the exception of February, have 31 days. February has 29 days in leap years, and 28 days otherwise. Leap years are divisible by four, and not divisible by 100 unless they are also divisible by 400. For example, 2004 and 2400 are leap years, but 2003 and 2100 are not. Jane also points out that there are only 14 possible calendars.

Definition

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

Constraints

  • year is between 2002 and 9999, inclusive

Examples

  1. 2002
    Returns: 2013
    Your 2002 Elvis calendar will be valid again in 2013. The following table shows the day of the week that September 8th falls on each year from 2002 to 2013. Year | Day -----+----- 2002 | Sunday 2003 | Monday 2004 | Wednesday 2005 | Thursday 2006 | Friday 2007 | Saturday 2008 | Monday 2009 | Tuesday 2010 | Wednesday 2011 | Thursday 2012 | Saturday 2013 | Sunday
  2. 2013
    Returns: 2019
    After 2013, your 2002 Elvis calendar will next be valid in 2019.
  3. 2008
    Returns: 2036
  4. 9999
    Returns: 10010
  5. 2525
    Returns: 2531
Back to all problems