TopCoder problem "YearProgressbar" used in SRM 420 (Division II Level Two)



Problem Statement

    

You are a big fan of New Year's Eve parties. The next one is not too far away, and you are already looking forward to it.

Then, one day, you wake up with a question: "Wait a moment, exactly how far away is it?"

To answer this question, you decided to implement a simple application: a year progress bar that will always show how much of the current year has already passed.

In this problem, your goal is to implement the most important part of this application: a function that gets a String currentDate, and returns the elapsed part of the year, as a percentage.

The variable currentDate will be of the form "Month DD, YYYY HH:MM" (quotes for clarity). Here, "Month" is the name of the current month, "YYYY" is a four-digit number representing the current year, and "DD", "HH", and "MM" are two-digit numbers (possibly with a leading zero) that represent the current day, hour and minute.

 

Definition

    
Class:YearProgressbar
Method:percentage
Parameters:String
Returns:double
Method signature:double percentage(String currentDate)
(be sure your method is public)
    
 

Notes

-The months of a normal year have 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, and 31 days.
-In leap years, the second month (February) has 29 days.
-A year is a leap year if (it is divisible by 400) or (it is divisible by 4, but not by 100).
-Ignore location-dependent changes to time flow such as daylight saving time.
-Your return value must have a relative or absolute error less than 1e-9.
 

Constraints

-currentDate will be of the form given in the problem statement.
-Month will be one of January, February, March, April, May, June, July, August, September, October, November, and December.
-YYYY will be between 1800 and 2600, inclusive.
-DD will be between 01 and the number of days in the given month (in the given year), inclusive.
-HH will be between 00 and 23, inclusive.
-MM will be between 00 and 59, inclusive.
 

Examples

0)
    
"January 01, 2008 00:00"
Returns: 0.0
This is the exact beginning of the year 2008; no time has elapsed yet.
1)
    
"December 31, 2007 23:59"
Returns: 99.99980974124807
One last minute of the year 2007 is remaining.
2)
    
"July 02, 2007 12:00"
Returns: 50.0
The exact half of a normal year is at noon on the second day of July.
3)
    
"July 02, 2008 00:00"
Returns: 50.0
On a leap year, the exact half of the year is the midnight between the first and the second of July.
4)
    
"May 10, 1981 00:31"
Returns: 35.348363774733635
The date and time when the problem setter was born :-)
5)
    
"January 31, 1900 00:47"
Returns: 8.228120243531203
Note that 1900 is not a leap year.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10058

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13511&pm=10058

Writer:

misof

Testers:

PabloGilberto , Olexiy , ivan_metelsky , zhuzeyuan

Problem categories:

Simple Math, Simple Search, Iteration, String Manipulation, String Parsing