TopCoder problem "GoodHours" used in TC China 08 - 1E (Division I Level Two)



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.

 

Definition

    
Class:GoodHours
Method:howMany
Parameters:String, String
Returns:int
Method signature:int howMany(String beforeTime, String afterTime)
(be sure your method is public)
    
 

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)
    
"11:11"
"11:11"
Returns: 1
Of course, 11:11 is good.
1)
    
"00:56"
"12:32"
Returns: 164
2)
    
"00:00"
"00:59"
Returns: 60
3)
    
"10:10"
"10:20"
Returns: 2
Only 10:10 and 10:20 are good here.
4)
    
"23:10"
"01:23"
Returns: 75
Good times here are 23:16, 23:23, 23:32, 00:00 ... 01:10, 01:20.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13677&pm=8448

Writer:

mateuszek

Testers:

PabloGilberto , Olexiy , Mike Mirzayanov , ivan_metelsky

Problem categories:

Brute Force, Simple Math