Poj 1002 487-3279

Source: Internet
Author: User

Source: http://poj.org/problem? Id = 1002]


487-3279
Time limit:2000 ms   Memory limit:65536 K
Total submissions:246666   Accepted:43755

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

Source

East central North America 1999


Convert the string to the corresponding "phone number" ~ according to the given conversion rules "~ Then, output the number of times each "phone number" appears in Lexicographic Order.


Question: I am killed! At the beginning, TLE went to death, and then Wa went to cry!

There are two reasons for TLE:

1. I first count the number of numbers and then sort them. This is very inefficient ~ Sort and then output directly.

2. As a dead CPP string

Wa is because of a small bug... I saw a group of test data on someone else's blog. I tried it and my program was not output. This is to identify the error. Add a statement to the AC


AC code:

#include<cstdio>#include<iostream>#include<algorithm>#include<cstring> #define Max 200005using namespace std;char num[]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','0','7','7','8','8','8','9','9','9','0'};int n;char Map[100],temp[100];struct Node{char s[50];}str[Max]; void init(){for(int i=0;i<26;i++)Map[i+'A']=num[i];return ;}int cmp(const void *s,const void *t){return strcmp( (*(Node *)s).s , (*(Node *)t).s);}int main(){scanf("%d",&n);init();for(int i=0;i<n;i++){int pos=0;scanf("%s",temp);for(int k=0;k<strlen(temp);k++){if(temp[k]=='-'||temp[k]=='Q'||temp[k]=='Z') continue;if(temp[k]>='0'&&temp[k]<='9') str[i].s[pos++]=temp[k];else if(temp[k]<='Z'&&temp[k]>='A') str[i].s[pos++]=Map[temp[k]];  if(pos==3) str[i].s[pos++]='-';}str[i].s[pos]='\0';} qsort(str,n,sizeof(str[0]),cmp); int pos=0; bool flag=true;for(int i=1;i<n;i++){if(!strcmp(str[i].s,str[i-1].s)){pos++;flag=false;if(i==n-1) cout<<str[i-1].s<<" "<<pos+1<<endl;}else if(pos){cout<<str[i-1].s<<" "<<pos+1<<endl;pos=0;}}if(flag) cout<<"No duplicates."<<endl;return 0;}



Poj 1002 487-3279

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.