Connection Status:
Competition Arena > CalendarRecycle
SRM 163 · 2003-09-08 · by Eeyore · Math, Simple Search, Iteration
Class Name: CalendarRecycle
Return Type: int
Method Name: useAgain
Arg Types: (int)
Problem Statement

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.

Constraints

  • year is between 2002 and 9999, inclusive
Examples
0)
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

1)
2013
Returns: 2019

After 2013, your 2002 Elvis calendar will next be valid in 2019.

2)
2008
Returns: 2036
3)
9999
Returns: 10010
4)
2525
Returns: 2531

Submissions are judged against all 110 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CalendarRecycle with a public method int useAgain(int year) · 110 test cases · 2 s / 256 MB per case

Submitting as anonymous