Programming Marathon: Phone number __ Programming

Source: Internet
Author: User
Topic Description
The picture above is a telephone of nine Sudoku, as you can see a number corresponding to some letters, so in foreign companies like to design the phone number to match their company name. 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 on behalf of 888-4567, 310-gino representative 310-4466.
Nowcoder just entered the foreign company, not accustomed to this way of naming, now give you a list of phone numbers, please help him convert to digital form of the number, and remove the duplicate parts.

Enter a description:
Input contains multiple sets of data. The

first row of each set of data contains a positive integer n (1≤n≤1024).

followed by n rows, each line contains a phone number, and the phone number consists of a hyphen "-", a number, and a capital letter.
There are no consecutive hyphens, and after the exclusion of hyphens, the length is always 7 (US phone number is only 7 digits).


Output Description:
For each set of inputs, output the standard digital form telephone number that is not duplicated in dictionary order, that is, "xxx-xxxx" form.

one row for each phone number, and a blank line after each set of data as a spacer.

Enter an example:
4873279
its-easy
888-4567
3-10-10-10
888-glop
tut-glop
310-gino
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
4
utt-help
tut-glop
310-gino
000-1213

Output Example:

310-1010
310-4466
487-3279
888-1200
888-4567
967-1111 000-1213 310-4466 888-4357
888-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;
	it++;
	} cout << Endl;
return 0; }





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.