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 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.
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
C++版本一

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
char convert(char c){
         if(c <= 'C') return '2';
         else if(c <= 'F') return '3';
         else if(c <= 'I') return '4';
         else if(c <= 'L') return '5';
         else if(c <= 'O') return '6';
         else if(c <= 'S') return '7';
         else if(c <= 'V') return '8';
         else if(c <= 'Y') return '9';
}
int main()
{
    int N;
    bool flag = false;
    cin >> N;
    map<string,int> telp_count;
    while(N--){
        string s,res;
        cin >> s;
        int i = 0;
       for(string::iterator s_it = s.begin();s_it != s.end();++s_it){
             if(*s_it >= '0' && *s_it <= '9') res.push_back(*s_it);
             if(*s_it >= 'A' && *s_it <= 'Z') res.push_back(convert(*s_it));
        }
        res.insert(3,1,'-');
        ++telp_count[res];
    }
    map<string,int>::iterator map_it = telp_count.begin();
    for(;map_it != telp_count.end();++map_it)
        if(map_it->second >= 2){
            flag = true;
            cout << map_it->first << " " << map_it->second << endl;
        }
    if(!flag)
        cout << "No duplicates." << endl;
    return 0;
}

C++版本二

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a,b;
int s[100010];
char ch[1010];
bool v;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",ch);
        for(int j=0;j<strlen(ch);j++){
            a=ch[j];
            if(a>='0'&&a<='9') s[i]+=a-'0',s[i]*=10;
            if(a>'9'){
                if(a=='A'||a=='B'||a=='C') a=2;
                if(a=='D'||a=='E'||a=='F') a=3;
                if(a=='G'||a=='H'||a=='I') a=4;
                if(a=='J'||a=='K'||a=='L') a=5;
                if(a=='M'||a=='N'||a=='O') a=6;
                if(a=='P'||a=='R'||a=='S') a=7;
                if(a=='T'||a=='U'||a=='V') a=8;
                if(a=='W'||a=='X'||a=='Y') a=9;
                if(a>1&&a<10) s[i]+=a,s[i]*=10;
            }
        }
        s[i]/=10;
    }
    sort(s+1,s+n+1);
    for(int i=1;i<=n;){
        a=0,b=i;
        while(s[i]==s[b]) a++,i++;
        if(a>1){
            v=1;
            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);
        }
    }
    if(!v) printf("No duplicates.\n");
    return 0;
}

C语言版本一

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
//#include <windows.h>
char convert(char c)
{
    if(isdigit(c))
        return c;
    else if(c <= 'C') return '2';
    else if(c <= 'F') return '3';
    else if(c <= 'I') return '4';
    else if(c <= 'L') return '5';
    else if(c <= 'O') return '6';
    else if(c <= 'S') return '7';
    else if(c <= 'V') return '8';
    else if(c <= 'Y') return '9';
}
int  compar(const void *a, const void *b)
{
    long *aa = (long *)a,*bb = (long *)b;
    return (*aa > *bb) ? 1 : (*aa == *bb ? 0 : -1);
}
int main(void)
{
    long n,*res,counter = 0 ,duplicate = 0;
    int i = 0 , j = 0,k = 0;
    char s[16],c;
    scanf("%ld",&n);
    res = (long *)malloc(sizeof(long)*n);
    while(j < n)
    {
        scanf("%s",s);
        for(i = k = 0;s[i]!='\0';i++)
        {
            if(s[i] == '-')
                continue;
            else
                s[k++] = convert(s[i]);
        }
        s[k] = '\0';        
        res[j++] = atol(s);
    }
    qsort(res,n,sizeof(long),compar);
    counter = 1;
    for(i = 1; i < n; i++)
    {
        if(res[i-1] == res[i])
        {
            counter++;
            if(i == n-1 && counter > 1)
            {
                printf("%0.3ld-%0.4ld %ld\n",res[i-1]/10000,res[i-1]%10000,counter);
                duplicate++;
                break;
            }
        }
        else if(res[i-1] != res[i])
        {
            if(counter >= 2)
            {
                printf("%0.3ld-%0.4ld %ld\n",res[i-1]/10000,res[i-1]%10000,counter);
                duplicate++;
            }
            counter = 1;
        }
    }
    if(duplicate == 0)
        printf("No duplicates.\n");
    //system("pause");
    return 0;
}

C语言版本二

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int cti(char n[8])
{
	return n[0]*10000000+n[1]*1000000+n[2]*100000+n[3]*10000+n[4]*1000+n[5]*100+n[6]*10+n[7];
	
	
}
int main(int argc, char *argv[]) {
	int n;
	scanf("%d",&n);
	char str[100000][8];
	
		int i,j;
		//输入 
		for(i=0;i<n;i++){
			j=0;
			while(j<7){
				char temp;
				scanf("%c",&temp);
				if('0'<=temp&&temp<='9'||'A'<=temp&&temp<='Y'&&temp!='Q'){
					
					if('A'<=temp&&temp<='Y'&&temp!='Q'){
				
					switch (temp){
						case 'A':str[i][j]='2';break;
						case 'B':str[i][j]='2';break;
						case 'C':str[i][j]='2';break;
						
						case 'D':str[i][j]='3';break;
						case 'E':str[i][j]='3';break;
						case 'F':str[i][j]='3';break;
						
						case 'G':str[i][j]='4';break;
						case 'H':str[i][j]='4';break;
						case 'I':str[i][j]='4';break;
						
						case 'J':str[i][j]='5';break;
						case 'K':str[i][j]='5';break;
						case 'L':str[i][j]='5';break;
						
						case 'M':str[i][j]='6';break;
						case 'N':str[i][j]='6';break;
						case 'O':str[i][j]='6';break;
						
						case 'P':str[i][j]='7';break;
						case 'R':str[i][j]='7';break;
						case 'S':str[i][j]='7';break;
						
						case 'T':str[i][j]='8';break;
						case 'U':str[i][j]='8';break;
						case 'V':str[i][j]='8';break;
						
						case 'W':str[i][j]='9';break;
						case 'X':str[i][j]='9';break;
						case 'Y':str[i][j]='9';break;
							
					}
					}else{str[i][j]=temp;
					}
					j++;
					
				}
			}
			
		}
		int strcount[100000] ;
		int strflag[100000];
		int k;
		//排序 
		for(i=0;i<n;i++){
			k=i;
			for(j=i+1;j<n;j++){
				
				if(cti(str[k])>cti(str[j]))
				k=j; 
			}
			if(k!=i){
				char temp[8];
				strcpy(temp,str[k]);
				strcpy(str[k],str[i]);
				strcpy(str[i],temp);
				
			}
		}
		//初始化 
		for(i=0;i<n;i++){
		
				strcount[i]=0;
				strflag[i]=0; 
		
		}
		//计数 
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				
				if(strcmp(str[i],str[j])==0)
				strcount[i]+=1; 
			}
		}
		//输出 
		int count=0;
		
			if(strcount[0]>1){
				for(j=0;j<7;j++){
					count++;
					printf("%c",str[0][j]);
					if(j==2) printf("-");
				}
				printf(" %d",strcount[0]);
				printf("\n");}
		for(i=1;i<n;i++){
            
			if(strcount[i]>1&&strcmp(str[i],str[i-1])!=0){
				for(j=0;j<7;j++){
					count++;
					printf("%c",str[i][j]);
					if(j==2) printf("-");
				}
				printf(" %d",strcount[i]);
				printf("\n");
			}		
		}
		if(count==0)printf("No duplicates.\n");
		

	
	
	return 0;
}

C语言版本X

//解法1
#include<iostream>
#include<string>
using namespace std;
int convert(char a)
{
    int flag=-1;
    if(a=='A'||a=='B'||a=='C'||a=='2')
    flag=2;
    if(a=='D'||a=='E'||a=='F'||a=='3')
    flag=3;  
    if(a=='G'||a=='H'||a=='I'||a=='4')
    flag=4;      
    if(a=='J'||a=='K'||a=='L'||a=='5')
    flag=5;  
    if(a=='M'||a=='N'||a=='O'||a=='6')
    flag=6;  
    if(a=='P'||a=='R'||a=='S'||a=='7')
    flag=7;
    if(a=='T'||a=='U'||a=='V'||a=='8')
    flag=8;
    if(a=='W'||a=='X'||a=='Y'||a=='9')
    flag=9;  
    if(a=='1')
    flag=1;
    if(a=='0')
    flag=0;
    return flag;      
}
char convert1(int a)
{
    char f;
      
    if(a==0)
        f='0';
    if(a==1)
        f='1';
      
    if(a==2)
        f='2';
      
    if(a==3)
        f='3';
      
    if(a==4)
        f='4';
      
    if(a==5)
        f='5';
          
    if(a==6)
        f='6';
      
    if(a==7)
        f='7';
      
    if(a==8)
        f='8';
      
    if(a==9)
        f='9';  
    return f;      
}
int main()
{
    string s;
    int p,q;
    string temp;
    int temp1;
    string a[10000];
    for(p=0;p<10000;p++)
        a[p]="";
    int sum;
    cin>>sum;
    int count=0;
    for(int i=0;i<sum;i++)
    {
        cin>>s;
        int j;
        int count1=0;
        for(j=0;j<s.length();j++)
        {
            temp1=convert(s[j]);
            if(temp1!=-1)
            {
                if(count1==3)
                {
                a[count]=a[count]+'-';  
                count1++;
                }
                a[count]=a[count]+convert1(temp1);
                count1++;
            }
        }
        count++;
    }
    int w[10000];
    string b[10000];
    int c[10000];
    for(int i=0;i<10000;i++)
    b[i]="";
    for(int i=0;i<count;i++)
    w[i]=1;
    int u=0;
for(int i=0;i<count;i++)
{
    if(w[i]==1)
    {
        int count2=1;
        for(int j=i+1;j<count;j++)
        {
            if(a[i]==a[j])
            {
            w[j]=0;
            count2++;
            }
        }
        if(count2>1)
        {
            b[u]=a[i];
            c[u]=count2;
            u++;          
        }
    }
}
    int d[100000];
    for(int z=0;z<u;z++)
    {
        d[z]=convert(b[z][0]);
    }
    int min;
    int y=0;
    for(int r=0;r<u;r++)
    {
    min=d[y];
    for(int z=0;z<u;z++)
    {
        if(d[z]<min)
        {
            min=d[z];
            y=z;
        }
    }
    cout<<b[y]<<" "<<c[y]<<endl;
    d[y]=100000;
    }
return 0;
}
 
//解法2
 
#include <iostream>
#include <map>
#include <string>
  
using namespace std;
  
int main()
{
    char szNumMap[] = "22233344455566670778889990";
    map<string,int> mResultMap;
    string strInputTemp;
    string strResult;
    int nCaseCount = 0;
    cin >> nCaseCount;
    while( nCaseCount > 0 )
    {
        cin >> strInputTemp;
        strResult.clear();
        for( string::size_type i = 0; i < strInputTemp.size(); ++i )
        {
            if ( strInputTemp[i] == '-' )   continue;
            if ( isdigit( strInputTemp[i] ) )
            {
                strResult += strInputTemp[i];
            }
            else
            {
                strResult += szNumMap[strInputTemp[i]-'A'];
            }
        }
        strResult.insert( 3, 1, '-' );
        mResultMap[strResult]++;
  
        --nCaseCount;
    }
  
    bool bRepeat = false;
    for ( map<string,int>::const_iterator it = mResultMap.begin();
        it != mResultMap.end(); ++it )
    {
        if ( it->second > 1 )
        {
            cout << it->first << " " << it->second << endl;
            bRepeat = true;
        }
    }
    if ( !bRepeat )
    {
        cout << "No duplicates." << endl;
    }
  
    return 0;
}
 
//解法3
typedef struct
{
    int identy;
    char str[9];
    int icount;
}Phone;
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100000
int cmp(const void *a, const void *b)
{
    int *x = (int *)a;
    int *y = (int *)b;
    return (*x) - (*y);
}
int main()
{
    int cnt = 0;   //存放电话号码个数
    int iter = 0;
    int Noduplicates = 0;  //有无重复号码的标志,为0则表示无重复
    int Sum = 0;
    int icount = 0;
    char ch;      // 接收键盘输入字符
    int *PHONE = (int *)malloc(sizeof(int) * (MAXSIZE + 10));
    scanf("%d",&cnt);
    getchar();
      
    //获取所有电话号码,转换为整型数据
    for(iter = 0; iter < cnt; iter++)
    {
        Sum = 0;
        ch = getchar();
        while(ch != '\n')
        {
            if(ch >= '0' && ch <= '9')
            {
                Sum = Sum * 10 + ch - '0' ;
            }
            else if(ch >= 'A' && ch <= 'P')
            {
                Sum = Sum * 10 + (ch - 65) / 3 + 2 ;
            }
            else if(ch >= 'R' && ch <= 'Y')
            {
                Sum = Sum * 10 + (ch - 66) / 3 + 2 ;
            }
            ch = getchar();
        }
        PHONE[iter] = Sum;
    }
      
    //用快排对电话号码排序
    qsort(PHONE, cnt, sizeof(int), cmp);
      
    //输出排好顺序的号码
    for(iter = 0, icount = 1; iter < cnt - 1 ; iter++)
    {
        icount = 1;
        //统计重复号码个数
        while(PHONE[iter] == PHONE[iter + 1])
        {
            iter++;
            icount++;
        }
        if(icount > 1)
        {
            Noduplicates = 1;
            printf("%03d-%04d %d\n",PHONE[iter] / 10000 ,PHONE[iter] % 10000 ,icount);
        }
    }
    if(Noduplicates == 0)
    {
        printf("No duplicates.\n");
    }
    getchar();
    return 0;
}
//解法4
 
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int cmp(const void *a, const void *b){
    return(*(int *)a-*(int *)b);
    }
int main(){
    char str[100];
    int num[26]={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, a[100005], l, sum, i, k, flag, t, s, j, p;
    scanf("%d", &n);
    getchar();
    k = 0;
    while (k!=n){
        gets(str);
        l = strlen(str);
        sum = 0;
        for (i=0; i<l; i++){
            if (str[i]>= '0' && str[i] <= '9'){
                sum = sum*10 + str[i]-'1'+1;
                continue;
            }
            if (str[i]>='A' && str[i]<='Z'){
                if (str[i] == 'Q' || str[i] == 'Z') continue;
                sum = sum * 10 + num[str[i]-'A'];
            }
        }
        a[k] = sum;
        k++;
    }
    a[k] = -1;
    qsort(a, k, sizeof(a[0]), cmp);
    t = a[0];
    flag = 0;
    i = 1;
    s = 1;
    while (i!=k+1){
        if (t == a[i]){
            s++;
            flag = 1;
        }else {
            if (s>1){
                p = 1000000;
                for(j=1; j<=3; j++){
                    printf("%d", t/p);
                    t = t%p;
                    p = p/10;
                }
                printf("-");
                
                p = 1000;
                for (j=1; j<=4; j++){
                    printf("%d", t/p);
                    t = t%p;
                    p = p/10;
                }
                printf(" %d\n", s);
            }
            t = a[i];
            s=1;
        }
        i++;
    }
    if (flag == 0){
        printf("No duplicates.\n");
    }
    return 0;
}