TopCoder problem "PulseDial" used in TCHS07 Alpha 2 (Division I Level Two)



Problem Statement

    

There are two methods used by phones to dial phone numbers, and one of them is pulse dial. In pulse dial, a phone number is represented as a sequence of pulses and pauses. Each maximal consecutive sequence of pulses represents a single digit. We will use the character '-' to denote a pulse and '*' to denote a pause. Digit '1' is represented as '-', digit '2' is represented as '--', and so on. Digit '0' consists of 10 dashes.

Given a String containing a sequence of pulses and pauses, return the phone number that it represents. If it is a 7-digit number, format the String as "XXX-XX-XX", and if it is an 11-digit number, prefix it with a '+' character: "+XXXXXXXXXXX". The phone number is guaranteed to contain exactly 7 or 11 digits.

 

Definition

    
Class:PulseDial
Method:toDigits
Parameters:String
Returns:String
Method signature:String toDigits(String raw)
(be sure your method is public)
    
 

Notes

-Maximal consecutive sequence of pulses are separated by one or more pauses.
-Pauses can start and finish input data.
 

Constraints

-raw will contain between 1 and 50 characters, inclusive.
-raw will contain only '-' and '*' characters.
-raw will contain 7 or 11 maximal consecutive sequences of '-'.
-Each maximal consecutive sequence of '-' will contain between 1 and 10 characters, inclusive.
 

Examples

0)
    
"---***-*--*-*--*-******--***"
Returns: "312-12-12"
1)
    
"-*--*-----*------*---*----*-"
Returns: "125-63-41"
2)
    
"--**--**--**--**--**--**--**--**--**--**--******"
Returns: "+22222222222"
3)
    
"*-*****-**-*--***--*****--***-***--**-**---**----*"
Returns: "+11122212134"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10716&pm=7547

Writer:

Mike Mirzayanov

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

String Parsing