Programming Marathon: Phone number

Source: Internet
Author: User

Title Description
is a telephone nine Gongge, as you can see a number corresponding to some letters, so in foreign companies like to design the phone number to their own company name corresponds. For example, the company's help desk number is 4357, because 4 corresponds to H, 3 corresponds to E, 5 corresponds to L, 7 corresponds to P, so 4357 is help. Similarly, Tut-glop represents 888-4567, 310-gino represents 310-4466.
Nowcoder just entered the foreign company, not accustomed to such a naming method, now give you a list of phone numbers, please help him to convert to digital form of the number, and remove the duplicated parts.

Input Description:
The input contains multiple sets of data. The first row of each set of data contains a positive integer n (1≤n≤1024). Immediately following n lines, each line contains a phone number, and the phone number is composed only of hyphens "-", numbers, and uppercase letters. There are no consecutive hyphens, and the length after the hyphen is excluded is always 7 (US phone number is only 7 digits).Output Description:
For each set of inputs, output the non-repeating standard number form phone number in dictionary order, which is the "xxx-xxxx" form. Each phone number is a row, and a blank line is output after each set of data as a spacer.

Input Example:
124873279its-easy888-45673-10-10-10888-gloptut-glop967-11-11310-ginof101010888-1200-4-8-7-3-2-7-9-487-32794utt-helptut-gl op310-gino000-1213

Output Example:

310-1010310-4466487-3279888-1200888-4567967-1111000-1213310-4466888-4357888-4567

Write your code here cpp#include <iostream> #include <string.h> #include <map>using namespace std; BOOL IsOk (char *str) {int count = 0;int n = strlen (str), char *p = Str;while (*p! = ') ') {if (*p = = '-') count++;p + +;} if (n-count! = 7) return False;return true;} BOOL Isnum (char ch) {return (CH-' 0 ') >= 0 && (CH-' 0 ') <= 9;} int main () {int N;char inputstr[1024]; char strbuff[256] = {0}; strbuff[' A '] = ' 2 '; strbuff[' B '] = ' 2 '; strbuff[' C '] = ' 2 '; strbuff[' D '] = ' 3 '; strbuff[' E '] = ' 3 '; strbuff[' F '] = ' 3 '; strbuff[' G '] = ' 4 '; strbuff[' H '] = ' 4 '; strbuff[' I '] = ' 4 '; strbuff[' J '] = ' 5 '; strbuff[' K '] = ' 5 '; strbuff[' L '] = ' 5 '; strbuff[' M '] = ' 6 '; strbuff[' N '] = ' 6 '; strbuff[' O '] = ' 6 '; strbuff[' P '] = ' 7 '; strbuff[' Q '] = ' 7 '; strbuff[' R '] = ' 7 '; strbuff[' S '] = ' 7 '; strbuff[' T '] = ' 8 '; strbuff[' U '] = ' 8 ';    strbuff[' V '] = ' 8 '; strbuff[' W '] = ' 9 '; strbuff[' X '] = ' 9 '; strbuff[' Y '] = ' 9 '; strbuff[' Z '] = ' 9 '; strbuff['-'] = '-';//cin >> n;while (cin>>n) {map<string, int> MP;WHIle (n--) {cin >> inputstr;string s;if (IsOk (INPUTSTR)) {Char *p = inputstr;while (*p! = ') {if (s.size () = = 3) {s + = '-'; continue;} Else{if (Isnum (*p)) {s + = *p;} Else{if (*p! = '-') s + = Strbuff[*p];}} p++;} Mp.insert (Pair<string, int> (S, 0));}} Map<string, int>:: Iterator it = Mp.begin (); while (It! = Mp.end ()) {cout << (*it). FIRST.C_STR () << endl;i t++;} cout << Endl;} return 0;}





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Programming Marathon: Phone number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.