TopCoder problem "DigitalDisplay" used in TCHS SRM 6 (Division I Level One)



Problem Statement

    A digital clock displays time in the format "DD:DD:DD" (quotes for clarity only), where each D is a single digit, and each pair of contiguous digits represents either the hour, minute, or second (each of these three units will occur exactly once). Unfortunately, we do not know the ordering of the time units, so need to figure out the number of valid ways to interpret the displayed time.



The hour must be between 01 and 12, inclusive, the minute must be between 00 and 59, inclusive, and the second must be between 00 and 59, inclusive.

For example, "21:23:01" can be intepreted in two ways: "minute:second:hour" or "second:minute:hour".

 

Definition

    
Class:DigitalDisplay
Method:waysToInterpret
Parameters:String
Returns:int
Method signature:int waysToInterpret(String display)
(be sure your method is public)
    
 

Constraints

-display will contain exactly 8 characters.
-display will be formatted as "DD:DD:DD" (quotes for clarity only), where each D is a digit ('0'-'9').
 

Examples

0)
    
"21:23:01"
Returns: 2
The example from the problem statement.
1)
    
"00:00:00"
Returns: 0
There are no valid interpretations here because the hour must be at least 01.
2)
    
"01:02:03"
Returns: 6
3)
    
"59:59:01"
Returns: 2
4)
    
"01:01:59"
Returns: 4
The four ways to interpret this are:

"hour:minute:second",

"hour:second:minute",

"minute:hour:second",

"second:hour:minute".

Problem url:

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

Problem stats url:

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

Writer:

myprasanna

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force, Simple Search, Iteration, String Manipulation