[ACM solution notes for dormitory cainiao] 487-3279

Source: Internet
Author: User
Source: Peking University ACM, question ID 1002, difficulty level.
Introduction Description
Businesses like to have memorable telephone numbers. one way to make a telephone number memorable is to have it spell a memorable word or phrase. for example, you can call the University of Waterloo by dialing the memorable tut-glop. sometimes only part of the number is used to spell a word. when you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-gino. another way to make a telephone number memorable is to group the digits in a memorable way. you cocould order your pizza from Pizza Hut by calling their ''three tens' number 3-10-10-10.

The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200 ). the keypad of a phone supplies the mapping of letters to numbers, 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

There is no mapping for Q or Z. hyphens are not dialed, and can be added and removed as necessary. the standard form of Tut-glop is 888-4567, the standard form of 310-gino is 310-4466, and the standard form of 3-10-10-10 is 310-1010.

Two telephone numbers are equivalent if they have the same standard form. (They dial the same number .)

Your company is compiling a directory of telephone numbers from local businesses. as part of the quality control process you want to check that no two (or more) businesses in the Directory have the same telephone number.

Input

The input will consist of one case. the first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. the remaining lines list the telephone numbers in the directory, with each number alone on a line. each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. exactly seven of the characters in the string will be digits or letters.

Output

Generate a line of output for each telephone number that appears more than once in any form. the line shoshould give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. arrange the output lines by telephone number in ascending lexicographical order. if there are no duplicates in the input print the line:

No duplicates.

Sample Input

124873279ITS-EASY888-45673-10-10-10888-GLOPTUT-GLOP967-11-11310-GINOF101010888-1200-4-8-7-3-2-7-9-487-3279

Sample output

310-1010 2487-3279 4888-4567 3
Question 1. Understand the question
  • Question:
Enter a group of phone numbers, some are represented by numbers, some are represented by letters, some are both numbers, there are uppercase letters, and some are "-". Our job is to use your eye-catching eyes to find the number of phone numbers that appear more than once, and output the number in alphabetical ascending order. For example, 310-1010, three-10-10-10-10 and f10101010 appear in total.
  • Input:
12 ~ Enter the number of phone numbers. The following 12 lines indicate the number of 12 phone numbers.
  • Output:
Phone numbers that appear more than once and the number of times they appear
2. the technical difficulty of answering this question is 0. You only need to understand the question one step at a time. The main line of code thinking is to define a map that uses the phone number as the key index, and each phone number appears as the key value. Map can be used to calculate the number of times each phone number appears, for example, it does not help us to obtain output in alphabetical ascending order. For more information about map, see C ++ premier.
The main task is to obtain the key index. To obtain a clean key index, we need
  • Converts uppercase letters into numbers given in the question;
  • Remove-
For more information, see the code. Complete code
# Include <stdlib. h >#include <iostream >#include <string ># include <map> using namespace STD; int main () {int A [26] = {0 }; int numberbit = 2; int stringcnt = 0; int phonenum = 0; int resultflag = 0; int Index = 0; string phonestring; string phoneonlynumbers; string hyphens = "-"; STD:: Map <string, int> stringlinknumber;/* 1. initialize */For (INT I = 0; I <26; I ++) {/* if it is Q or Z, no corresponding number key */If (16 = I) | (25 = I ))){ Continue;} else {A [I] = numberbit; stringcnt ++; If (3 = stringcnt) {numberbit ++; stringcnt = 0; Continue ;}}} /* 2. obtain the input information */CIN> phonenum; If (phonenum> 100000) {cout <"no duplicates. "<Endl ;}for (INT I = 0; I <phonenum; I ++) {phonestring =" "; phoneonlynumbers = ""; /* 2.1 read the phone number into phonestring */CIN> phonestring; For (Int J = 0; j <phonestring. size (); j ++) {/* If A hyphen (-) is encountered, skip */If ('-' = phonestring [J]) {continue;} else {/* if it contains uppercase letters, convert it */If (phonestring [J]> = 'A ') & (phonestring [J] <= 'Z') {Index = phonestring [J]-'A '; phoneonlynumbers + = A [Index] + '0';} else {/* does not contain letters or dashes, then directly splice */phoneonlynumbers + = phonestring [J] ;}} phoneonlynumbers. insert (3, "-");/* 2.2 assign the telephone number string containing only numbers to the subscript of map, add */++ stringlinknumber [phoneonlynumbers];}/* 3. sort the phone numbers in map in alphabetical order */STD: Map <string, int>: Iterator it = stringlinknumber. Begin (); For (; it! = Stringlinknumber. end (); It ++) {STD: pair <string, int> _ p = * it; if (1 <_ p. second) {STD: cout <_ p. first <"" <_ p. second <Endl; resultflag = 1 ;}} if (0 = resultflag) {cout <"no duplicates. "<Endl;} return 0 ;}

Summary and some of the gains through this topic, you can learn about map and the string content in C ++.








[ACM solution notes for dormitory cainiao] 487-3279

Related Article

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.