TopcoderArchiveVisit Topcoder
SRM14 Jun 2002
SRM 98

TelNum

Problem statement, definition, constraints, and public examples.

Problem Statement

Consider a 7-digit combination as a potential local telephone number. We would like to classify all 7-digit combinations as one of the following types: OPERATOR, LONG DISTANCE, EMERGENCY, MOVIE, VANITY or REGULAR.

  • OPERATOR - all numbers that start with 0 (you can't use such a combination for a phone number, as you would get an operator after dialing the first 0).
  • LONG DISTANCE - all numbers that start with 1 (you can't use such a combination for a local phone number, as the system would expect this to be a LONG DISTANCE call, and would wait for 4 more digits).
  • EMERGENCY - all numbers that start with N11, where N is a digit between 2 and 9, inclusive (we often use 911 and 411, but others are also reserved for special use).
  • MOVIE - all numbers that start with 555 (those numbers are fake numbers that are used as pretend phone numbers in the movies or on TV).
  • VANITY - these are numbers not included in the above categories that many businesses dream to have as they are easy to remember. More precisely, these are the numbers where the last 4 digits are easy to remember. There are the following types of vanity numbers:
    1) one digit repeated four times, as in 4444;
    2) numbers with only 2 distinct digits such as 2223, or 4545;
    3) digits in strictly increasing order (each digit is 1 plus the previous digit) as in 2345;
    4) digits in strictly decreasing order (each digit is the previous digit minus 1) as in 3210
  • REGULAR - all other numbers
NOTE: The number 432-1098, should return "REGULAR" as there is no wrap around in increasing or decreasing vanity numbers. "0" is not regarded as 9+1.

Your task is, given a String representing a 7-digit combination, return its type in our classification. An input String will be given in the following format: "NNN-NNNN", where each N is a digit between 0 and 9 inclusive.

Definition

Class:
TelNum
Method:
type
Parameters:
String
Returns:
String
Method signature:
String type(String telNum)
(be sure your method is public)

Constraints

  • telNum contains exactly 8 characters
  • The fourth character of telNum is a dash '-', all other characters are digits ('0'-'9').

Examples

  1. "222-2222"
    Returns: "VANITY"
  2. "123-4567"
    Returns: "LONG DISTANCE"
  3. "258-2583"
    Returns: "REGULAR"
  4. "432-1098"
    Returns: "REGULAR"
  5. "000-0000"
    Returns: "OPERATOR"
  6. "555-0000"
    Returns: "MOVIE"
  7. "911-9876"
    Returns: "EMERGENCY"
Back to all problems