A community theater's casting office keeps a running list of callback numbers submitted by auditioning actors. Office policy accepts a callback number only if it is written in one of two approved formats: three digits, a hyphen, three digits, a hyphen, and four digits, written as DDD-DDD-DDDD; or an area code in parentheses followed by a single space, three digits, a hyphen, and four digits, written as (DDD) DDD-DDDD. Every other way of writing a number — missing or extra hyphens, a missing space after the closing parenthesis, letters, or any other punctuation — must be rejected. Given the submitted entries in the order they arrived, print only the entries that exactly match one of the two approved formats, each on its own line, in their original relative order.
Print each entry that matches one of the two approved formats, one per line, in the same order they appeared in the input. If no entry qualifies, print nothing at all.
Example 1
Input
5 415-555-2671 (415) 555-2671 415-5-2671 555-4321 (415)555-2671
Expected
415-555-2671 (415) 555-2671
Explanation
Entry 1 matches DDD-DDD-DDDD. Entry 2 matches (DDD) DDD-DDDD, including the required space after the closing parenthesis. Entry 3 has only one digit in its middle group, entry 4 is missing an entire group, and entry 5 is missing the required space after ')'. Only entries 1 and 2 are printed, in that order.
Example 2
Input
3 abc-def-ghij 123-456-78900 (123 456-7890
Expected
(empty)Explanation
None of the three entries qualify: the first uses letters instead of digits, the second has five digits in its last group instead of four, and the third is missing its closing parenthesis and hyphen. Since nothing matches, no output is produced.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →