487-3279(电话号码)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 287196 | Accepted: 51568 |
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 could 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.
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 should 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.
No duplicates.
Sample Input
12 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
Source
题目描述
一串由长长的数字组成的电话号码通常很难记忆。为了方便记忆,有种方法是用单词来方便记忆。例如用“Three Tens”来记忆电话3-10-10-10。
电话号码的标准形式是七位数字,中间用连字号分成前三个和后四个数字(例如:888-1200)。电话号码可以用字母来表示。以下是字母与数字的对应:
A,B和C对应2
D,E和F对应3
G,H和I对应4
J,K和L对应5
M,N和O对应6
P,R和S对应7
T,U和V对应8
W,X和Y对应9
你会发现其中没有字母Q和Z。电话中的连字号是可以忽略。例如TUT-GLOP的标准形式是888-4567,310-GINO的标准形式是310-4466,3-10-10-10的标准形式是310-1010。
如果两个电话号码的标准形式是一样的,那么这两个电话号码就是一样的。
现在有一本电话簿,请从中找出哪些电话号码是重复的。
输入输出格式
输入格式:
第一行一个正整数N,表示有多少个电话号码。
以下N行,每行一个电话号码,电话号码由数字、大写字母(除Q、Z)和连字符组成。电话号码长度不会超过1000。所有电话号码都合法。
输出格式:
将所有重复的电话号码按字典序以标准形式输出,并且在每个电话号码后跟一个整数,表示该电话号码共出现了多少次,电话号码和整数间用一个空格隔开。不要输出多余空行。
如果没有重复的电话号码,则输出:No duplicates.
输入输出样例
输入样例#1:
3 TUT-GLOP 3-10-10-10 310-1010
输出样例#1:
310-1010 2
说明
【数据范围】
对于30%的数据,N<=20。
对于50%的数据,N<=10000。
对于100%的数据,N<=100000。
思路:模拟+排序
没注意到字典序,想用map,坑了一把。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int n,a,b; 6 int s[100010]; 7 char ch[1010]; 8 bool v; 9 int main(){ 10 scanf("%d",&n); 11 for(int i=1;i<=n;i++){ 12 scanf("%s",ch); 13 for(int j=0;j<strlen(ch);j++){ 14 a=ch[j]; 15 if(a>='0'&&a<='9') s[i]+=a-'0',s[i]*=10; 16 if(a>'9'){ 17 if(a=='A'||a=='B'||a=='C') a=2; 18 if(a=='D'||a=='E'||a=='F') a=3; 19 if(a=='G'||a=='H'||a=='I') a=4; 20 if(a=='J'||a=='K'||a=='L') a=5; 21 if(a=='M'||a=='N'||a=='O') a=6; 22 if(a=='P'||a=='R'||a=='S') a=7; 23 if(a=='T'||a=='U'||a=='V') a=8; 24 if(a=='W'||a=='X'||a=='Y') a=9; 25 if(a>1&&a<10) s[i]+=a,s[i]*=10; 26 } 27 } 28 s[i]/=10; 29 } 30 sort(s+1,s+n+1); 31 for(int i=1;i<=n;){ 32 a=0,b=i; 33 while(s[i]==s[b]) a++,i++; 34 if(a>1){ 35 v=1; 36 printf("%d%d%d-%d%d%d%d %d\n",s[b]/1000000%10,s[b]/100000%10,s[b]/10000%10,s[b]/1000%10,s[b]/100%10,s[b]/10%10,s[b]%10,a); 37 } 38 } 39 if(!v) printf("No duplicates.\n"); 40 return 0; 41 }
果然模拟题才是难题呀。
题目来源:poj,洛谷