意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

POJ1002487-3279直接哈希模拟

来源:恒创科技 编辑:恒创科技编辑部
2024-02-04 01:20:59


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.

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.


POJ1002487-3279直接哈希模拟

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.

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





题意:给出若干的字符串,按照题目要求,字母转为对应数字,然后都化成xxx-xxxx的电话形式



让你求出所有出现次数大于等于2的电话号并将其按照号码大小排序输出。





坑点:1.真的坑了我好久,Q和Z会出现的,而且表示为0.



2.也就是1的说明,000-0000是可以存在的,所以不能简单用数字存下来,不然就变0了。



3.C++字符串排序我不会。。。我就把数字取出来再排序了。








#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<string>
#define ll long long
#define N 100005
#define M 10000000
using namespace std;
int anslen,hash[M],zh[30];
struct ff{
int aaa; //aaa是数值用来sort
char ans[10]; //用来输出
}aa[N];
bool cmp(ff x,ff y){
return x.aaa<y.aaa;
}
int main(){
anslen=0;
int n;
zh[0]=zh[1]=zh[2]=2;
zh[3]=zh[4]=zh[5]=3;
zh[6]=zh[7]=zh[8]=4;
zh[9]=zh[10]=zh[11]=5;
zh[12]=zh[13]=zh[14]=6;
zh[15]=zh[17]=zh[18]=7;
zh[19]=zh[20]=zh[21]=8;
zh[22]=zh[23]=zh[24]=9;
scanf("%d",&n);
while (n--){
char s[100];
int a[10];
scanf("%s",s);
int len=strlen(s),lena=0;
for (int i=0;i<len;i++)
if (s[i]>='A' && s[i]<='Z')
s[i]=char(zh[s[i]-65]+48);
for (int i=0;i<len;i++)
if (s[i]>='0' && s[i]<='9')
a[++lena]=s[i]-48;
int num=0;
for (int i=1;i<=lena;i++)
num=num*10+a[i];
if (lena!=7) continue;
if (hash[num]==1){ //只有7位,直接哈希,不要管什么map
anslen++;
for (int i=1;i<=lena;i++)
aa[anslen].ans[i]=a[i];
aa[anslen].aaa=num;
}
hash[num]++;
}
if (!anslen) printf("No duplicates.\n");
sort(aa+1,aa+1+anslen,cmp);
for (int i=1;i<=anslen;i++){
for (int j=1;j<=3;j++) printf("%d",aa[i].ans[j]);
printf("-");
for (int j=4;j<=7;j++) printf("%d",aa[i].ans[j]);
printf(" %d\n",hash[aa[i].aaa]);
}
return 0;
}





上一篇: ZJOI2017 NGU! 下一篇: 手机怎么远程登录云服务器?