Statistics

Problem Statement for "YearProgressbar"

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

  1. "January 01, 2008 00:00"

    Returns: 0.0

    This is the exact beginning of the year 2008; no time has elapsed yet.

  2. "December 31, 2007 23:59"

    Returns: 99.99980974124807

    One last minute of the year 2007 is remaining.

  3. "July 02, 2007 12:00"

    Returns: 50.0

    The exact half of a normal year is at noon on the second day of July.

  4. "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.

  5. "May 10, 1981 00:31"

    Returns: 35.348363774733635

    The date and time when the problem setter was born :-)

  6. "January 31, 1900 00:47"

    Returns: 8.228120243531203

    Note that 1900 is not a leap year.

  7. "January 11, 1800 09:46"

    Returns: 2.8512176560121767

  8. "February 20, 1900 07:53"

    Returns: 13.788622526636225

  9. "March 08, 2000 09:12"

    Returns: 18.410746812386158

  10. "April 02, 2100 19:02"

    Returns: 25.148782343987822

  11. "May 24, 2200 11:19"

    Returns: 39.307267884322684

  12. "June 17, 2300 18:00"

    Returns: 45.95890410958904

  13. "July 05, 2400 11:16"

    Returns: 50.94793564055859

  14. "August 02, 2500 21:27"

    Returns: 58.601027397260275

  15. "September 03, 2600 14:50"

    Returns: 67.29261796042618

  16. "October 20, 2548 17:55"

    Returns: 80.25861414693382

  17. "November 13, 2133 05:18"

    Returns: 86.63584474885843

  18. "December 23, 2296 19:16"

    Returns: 97.76032179720706

  19. "January 18, 1824 21:33"

    Returns: 4.89014116575592

  20. "February 08, 2417 14:37"

    Returns: 10.57781582952816

  21. "March 02, 1901 05:30"

    Returns: 16.501141552511417

  22. "April 17, 2566 20:20"

    Returns: 29.273211567732112

  23. "May 22, 2219 04:50"

    Returns: 38.68531202435312

  24. "June 02, 2076 20:45"

    Returns: 42.03950364298725

  25. "July 05, 2405 22:05"

    Returns: 50.937024353120236

  26. "August 03, 1804 12:17"

    Returns: 58.883006982392224

  27. "September 16, 2475 14:45"

    Returns: 70.85331050228311

  28. "October 27, 2243 03:44"

    Returns: 81.96042617960426

  29. "November 21, 2329 12:48"

    Returns: 88.91324200913243

  30. "December 01, 2498 03:24"

    Returns: 91.54566210045661

  31. "January 10, 2438 12:19"

    Returns: 2.6063546423135464

  32. "February 05, 2042 19:48"

    Returns: 9.815068493150683

  33. "March 19, 1816 06:06"

    Returns: 21.38091985428051

  34. "April 30, 1836 02:10"

    Returns: 32.81155130540376

  35. "May 12, 2591 17:21"

    Returns: 36.0884703196347

  36. "June 03, 1977 04:12"

    Returns: 41.96575342465753

  37. "January 01, 2400 00:01"

    Returns: 1.8973891924711593E-4

  38. "January 31, 2000 00:47"

    Returns: 8.205639040680024

  39. "February 02, 2007 12:00"

    Returns: 8.904109589041095

  40. "July 02, 2000 12:00"

    Returns: 50.13661202185792

  41. "July 02, 2300 12:00"

    Returns: 50.0

  42. "September 02, 2007 12:00"

    Returns: 66.98630136986301

  43. "March 10, 1900 12:05"

    Returns: 18.768074581430746

  44. "May 10, 2100 00:31"

    Returns: 35.348363774733635

  45. "January 01, 2008 00:10"

    Returns: 0.0018973891924711599

  46. "September 11, 2400 10:42"

    Returns: 69.52071948998179

  47. "November 20, 1900 23:55"

    Returns: 88.76617199391171

  48. "February 18, 2000 23:16"

    Returns: 13.379629629629632

  49. "January 12, 2000 00:00"

    Returns: 3.0054644808743167

  50. "March 01, 2000 00:00"

    Returns: 16.39344262295082

  51. "May 01, 2000 00:00"

    Returns: 33.060109289617486

  52. "December 31, 1900 23:59"

    Returns: 99.99980974124807

  53. "July 02, 2100 00:00"

    Returns: 49.863013698630134

  54. "November 20, 1900 00:00"

    Returns: 88.4931506849315

  55. "February 17, 1990 03:11"

    Returns: 12.913051750380516

  56. "February 12, 2004 10:34"

    Returns: 11.595704310868244

  57. "August 01, 2008 00:00"

    Returns: 58.19672131147541

  58. "February 15, 2008 12:07"

    Returns: 12.433022161505768

  59. "April 29, 1900 00:47"

    Returns: 32.337709284627095

  60. "January 23, 2000 23:23"

    Returns: 6.277132665452337

  61. "February 29, 2008 23:55"

    Returns: 16.392493928354586

  62. "January 12, 2004 10:34"

    Returns: 3.125758955676988

  63. "July 25, 2000 01:11"

    Returns: 56.29762446873102

  64. "August 09, 2007 00:34"

    Returns: 60.28044140030441

  65. "February 01, 2008 00:00"

    Returns: 8.469945355191257

  66. "November 30, 2000 23:59"

    Returns: 91.52986490588947

  67. "October 03, 2000 00:00"

    Returns: 75.40983606557377

  68. "March 13, 2000 14:51"

    Returns: 19.841188524590162

  69. "December 31, 2000 23:59"

    Returns: 99.99981026108073

  70. "December 31, 2200 23:59"

    Returns: 99.99980974124807

  71. "January 11, 2008 00:00"

    Returns: 2.73224043715847

  72. "April 25, 2000 11:23"

    Returns: 31.55035670916818

  73. "December 31, 2100 23:59"

    Returns: 99.99980974124807


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: