ACMACM Practice-Phone book Check heavy __ACM

Source: Internet
Author: User
1. Description of the problem

487-3279

Time Limit: 2000MS Memory Limit: 65536K
Total submissions: 301651 accepted: 53967

Description companies like to use phone numbers that are easy to remember. One way to make a phone number easy to remember is to write it as a word or phrase that is easy to remember. For example, when you need to call the University of Waterloo, you can call Tut-glop. Sometimes, only some numbers in the phone number are spelled as words. When you return to the hotel at night, you can make a pizza by dialing 310-gino to Gino's. Another way to make your phone numbers easier to remember is to group numbers in a good and memorable way. You can order a pizza from them by dialing the "three ten" numbers in Pizza Hut at 3-10-10-10.

The standard format for a phone number is a seven-bit decimal number, and there is a connector between the third and fourth digits. The telephone dial provides a mapping from letter to number, and the mapping relationship is as follows:
A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and y map to 9

Q and z do not map to any numbers, hyphens do not need dialing, and can be added and deleted arbitrarily. The standard format for Tut-glop is that the standard format for 888-4567,310-gino is the 310-4466,3-10-10-10 standard format is 310-1010.

If two numbers have the same standard format, then they are equivalent (same dialing)

Your company is writing a phone book for a local company. As part of quality control, you want to check whether two or more companies have the same phone number.

Input format is that the first line is a positive integer, specifying the number of numbers in the phone number (up to 100000). Each of the remaining lines is a phone number. Each phone number consists of numbers, uppercase letters (except Q and z), and connectors. There will be just 7 digits or letters in each phone number.

Output produces a single line of output for each number that repeats, and a standard format for the number that follows a space followed by its number of repetitions. If there are multiple duplicate numbers, the number is printed in ascending order of the dictionary. If there is no duplicate number in the input data, the output line:
No duplicates.

Sample Input

4873279
its-easy
888-4567
3-10-10-10
888-glop
tut-glop 967-11-11 310-gino
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279

Sample Output

310-1010 2
487-3279 4
888-4567 3

2. Select data Structure

You can use string type to store numbers in non-standard formats, and map to store phone numbers and duplicates, map itself key value key sort

3. Core code block

#include <iostream> #include <string> #include <map> using namespace std;
void Strstd (string& str);
void Leavesampletel ();

void Printbook ();

Map<string, int> Telbook;
	int main () {map<string, int>::iterator it;
	String str;
	int num = 0;
	CIN >> Num;
		while (num--) {cin >> str;

		STRSTD (str);
		it = Telbook.find (str);
		if (it!= telbook.end ()) {(it->second) + +;
		else {Telbook.insert (make_pair<string, int> (str, 1));
	} Leavesampletel ();
	Printbook ();
return 0; }//formatted input void strstd (string& str) {for (int i = 0; i < str.length (); i++) {if (str[i] = = '-') {Str.erase
			(i, 1);
			i--;
		Continue
		} if (Str[i] >= ' A ' && str[i] <= ' C ') str[i] = ' 2 ';
		if (Str[i] >= ' D ' && str[i] <= ' F ') str[i] = ' 3 ';
		if (Str[i] >= ' G ' && str[i] <= ' i ') str[i] = ' 4 ';
		if (Str[i] >= ' J ' && str[i] <= ' L ') str[i] = ' 5 '; if (Str[i] >= ' M ' &&Amp
		Str[i] <= ' O ') str[i] = ' 6 ';
		if (Str[i] >= ' P ' && str[i] <= ' S ') str[i] = ' 7 ';
		if (Str[i] >= ' T ' && str[i] <= ' V ') str[i] = ' 8 ';
	if (Str[i] >= ' W ' && str[i] <= ' Y ') str[i] = ' 9 ';
} str.insert (3, "-");
	//Leave the same call record and sort void Leavesampletel () {map<string, int>::iterator it = Telbook.begin ();
		while (it!= telbook.end ()) {if (It->second = 1) {telbook.erase (it++);//map Erase in continue;
	} it++;
	}//Format output void Printbook () {map<string, int>::iterator it = Telbook.begin ();
	if (it = = Telbook.end ()) cout << "No duplicates." << Endl;
	for (; it!= telbook.end (); it++) {cout << it->first << "" << it->second << Endl; }
}

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.