Connection Status:
Competition Arena > GoodHours
TC China 08 - 1E · 2008-11-23 · by mateuszek · Brute Force, Simple Math
Class Name: GoodHours
Return Type: int
Method Name: howMany
Arg Types: (string, string)
Problem Statement

Problem Statement

Johnny likes to watch the clock. He likes some moments more than others. The time "HH:MM" is good if you can split the four digits into two adjacent groups such that the products of the digits within each group are equal. Each group must contain at least one digit, so there are totally 3 possible ways to do the split: "H" and "H:MM", "HH" and "MM", or "HH:M" and "M". For example, "22:28" is good because you can split it into "22:2" and "8", and 2 * 2 * 2 = 8. "23:32" and "10:00" are also good, while "23:45" and "12:42" are not.


You are given two Strings, beforeTime and afterTime, each formatted as "HH:MM" (quotes for clarity). The two times are less than 24 hours apart. Return the number of good times between beforeTime and afterTime, inclusive.

Constraints

  • beforeTime and afterTime will both be formatted as "HH:MM" (quotes for clarity), where HH is a two digit integer between 00 and 23, inclusive, and MM is a two digit integer between 00 and 59, inclusive.
Examples
0)
"00:00"
"23:59"
Returns: 279
1)
"11:11"
"11:11"
Returns: 1

Of course, 11:11 is good.

2)
"12:22"
"12:21"
Returns: 279
3)
"12:32"
"11:31"
Returns: 272
4)
"00:56"
"12:32"
Returns: 164
6)
"10:10"
"10:20"
Returns: 2

Only 10:10 and 10:20 are good here.

53)
"23:10"
"01:23"
Returns: 75

Good times here are 23:16, 23:23, 23:32, 00:00 ... 01:10, 01:20.

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

Coding Area

Language: C++17 · define a public class GoodHours with a public method int howMany(string beforeTime, string afterTime) · 68 test cases · 2 s / 256 MB per case

Submitting as anonymous