UVa 755 - 487--3279
2012-05-30 21:22
351 查看
487-3279 |
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.
Input
The first line of the input contains the number of datasets in the input. A blank line follows. The first line of each dataset 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. There's a blank line between datasets.
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. Arrangethe output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:
No duplicates.
Print a blank line between datasets.
Sample Input
1 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
对于这道题真是折磨了我很长时间,一开始没用快排,结果超时,然后考虑了快排结果还超时,然后把字符串的电话号码计算成数字这样在用快排,还超时,看到了网上说还要用哈希,用了还超时,看别人的结题报告思路和自己的差不多,只是我是先把电话号码归并,统计个数在排序然后输出,他们的思路是先排序,然后在统计个数,在统计个数的过程中输出数据,这样我想了想确实是节省了时间,而我的思路在将电话号码归并统计的过程中浪费了很多时间。不如先排序,然后在统计个数的时候输出。
#include <stdio.h> #include <string.h> #include <stdlib.h> int a[100010]; char s1[1000]; int b[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; int cmp(const void *a,const void *b) { return (*(int *)a-*(int *)b); } int main() { int i,j,n,s,l,k,sum,flag,t; scanf("%d",&t); while(t--) { scanf("%d",&n); getchar(); flag=0; for(i=0;i<=n-1;i++) { gets(s1); l=strlen(s1); sum=0; for(j=0;j<=l-1;j++) { if(s1[j]>='0'&&s1[j]<='9') { sum=sum*10+s1[j]-'0'; }else if(s1[j]>='A'&&s1[j]<'Z'&&s1[j]!='Q') { sum=sum*10+b[s1[j]-'A']; } } a[flag]=sum; flag+=1; } qsort(a,flag,sizeof(a[0]),cmp); k=0; for(i=0;i<=flag-1;) { s=1; for(j=i+1;j<=flag-1;j++) { if(a[i]==a[j]) { s+=1; }else { break; } } if(s>1) { k=1; printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,s); } i=j; } if(k==0) { printf("No duplicates.\n"); } if(t) { printf("\n"); } } return 0; }
相关文章推荐
- UVa 755 - 487--3279
- UVA - 755 487--3279
- UVA 755 (暑假-排序、检索(2)-D-487--3279 )
- UVA755- 487-3279
- UVA - 755 487--3279
- UVA 755 - 487--3279
- uva 755 (487--3279)排序
- UVa: 755 - 487--3279
- UVa_755 - 487--3279
- ZOJ1159 UVA755 UVALive5420 487-3279【查表】
- uva 755 - 487--3279
- UVa 755 - 487--3279
- UVA 755 487--3279
- UVa 755 487--3279解题报告
- UVA 755 - 487--3279
- UVa 755 - 487--3279
- UVA 755-487--3279
- 开篇,UVA 755 && POJ 1002 487--3279 (Trie + DFS / sort)
- uva 755 - 487--3279
- UVA 755 487-3279