TelNum
SRM 98 · 2002-06-14 · by axchma
SRM 98 · 2002-06-14 · by axchma
Problem Statement
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
Your task is, given a
Constraints
- telNum contains exactly 8 characters
- The fourth character of telNum is a dash '-', all other characters are digits ('0'-'9').
Examples
0)
"222-2222" Returns: "VANITY"
1)
"123-4567" Returns: "LONG DISTANCE"
2)
"258-2583" Returns: "REGULAR"
3)
"432-1098" Returns: "REGULAR"
4)
"011-0000" Returns: "OPERATOR"
Submissions are judged against all 90 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class TelNum with a public method string type(string telNum) · 90 test cases · 2 s / 256 MB per case