#include <stdio.h>#include <string.h>#include <malloc.h> int main() { int n; int i,j; int iCurr; int count; char **str; char **str1; int no_duplicates=1; int *indices; void sort_string(char **s,int i,int * indices); scanf("%d",&n); str=(char**) malloc(sizeof(char*)*n); str1=(char**) malloc(sizeof(char*)*n); indices=(int*) malloc(sizeof(int)*n); for(i=0;i<n;i++) { *(str+i)=(char*) malloc(sizeof(char)*30); *(str1+i)=(char*) malloc(sizeof(char)*8); } for(i=0;i<n;i++) scanf("%s",*(str+i)); for(i=0;i<n;i++) { j=0; count=0; while(count<7) { if(str[i][j]!='-') { switch(str[i][j]) { case 'A': case 'B': case 'C': str1[i][count]='2'; break; case 'D': case 'E': case 'F': str1[i][count]='3'; break; case 'G': case 'H': case 'I': str1[i][count]='4'; break; case 'J': case 'K': case 'L': str1[i][count]='5'; break; case 'M': case 'N': case 'O': str1[i][count]='6'; break; case 'P': case 'R': case 'S': str1[i][count]='7'; break; case 'T': case 'U': case 'V': str1[i][count]='8'; break; case 'W': case 'X': case 'Y': str1[i][count]='9'; break; default: str1[i][count]=str[i][j]; break; } count++; str1[i][7]='\0'; } j++; } } for(i=0;i<n;i++) free(*(str+i)); free(str); sort_string(str1,n,indices); for(i=0;i<n;i++) { iCurr=i; count=1; for(j=i+1;j<n;j++) { if(j==n) break; if(strcmp(str1[indices[i]],str1[indices[j]])) { i=j-1; break; } else count++; } if(count>1) { for(j=0;j<3;j++) printf("%c",str1[indices[iCurr]][j]); printf("%c",'-'); for(j=3;j<7;j++) printf("%c",str1[indices[iCurr]][j]); printf(" %d\n",count); no_duplicates=0; } if(j==n) break; } if(no_duplicates) printf("No duplicates."); for(i=0;i<n;i++) free(*(str1+i)); free(str1); free(indices); return 0;} void sort_string(char **s,int n,int *indices){ int i,j; int temp; for(i=0;i<n;i++) *(indices+i)=i; for(i=n-1;i>=1;i--) { for(j=0;j<=i-1;j++) { if(strcmp(s[indices[j]],s[indices[j+1]])>0) { temp=indices[j]; indices[j]=indices[j+1]; indices[j+1]=temp; } } }}

评论