POJ 1002 487-3279

  
    
#include " stdio.h "
#include
" ctype.h "
#include
" string.h "
#include
" stdlib.h "
int n,max = - 1 ,maxI;
char str[ 80 ],telNum[ 100000 ][ 9 ];
char map[ 27 ] = " 22233344455566677778889999 " ;

int cmp( const void * a, const void * b){
return (strcmp(( char * )a,( char * )b));
}

void toNum( int num){ //解析数字
int i,j;
for (i = 0 ,j = 0 ; j < 8 ;){
if (j == 3 ){
telNum[num][j]
= ' - ' ;
j
++ ;
continue ;
}
if (isdigit(str[i])){
telNum[num][j]
= str[i];
i
++ ;
j
++ ;
continue ;
}
if (isalpha(str[i])){
telNum[num][j]
= map[str[i] - ' A ' ];
i
++ ;
j
++ ;
continue ;
}
if (str[i] == ' - ' ){
i
++ ;
continue ;
}
}
telNum[num][j]
= ' \0 ' ;
}

void in (){
scanf(
" %d " , & n);
int i;
for (i = 0 ; i < n; i ++ ){
scanf(
" %s " ,str);
toNum(i);
}
}

void print(){
int i,j,flag = 0 ;
for (i = 0 ; i < n; ){
j
= i;
while (i < n && ! strcmp(telNum[i],telNum[j]))
i
++ ;
if (i - j > 1 ){
printf(
" %s %d\n " ,telNum[j],i - j);
flag
= 1 ;
}
}
if ( ! flag)
printf(
" No duplicates.\n " );
}


void print1(){
int i,j;
for (i = 0 ; i < n; i ++ ){
printf(
" %s\n " ,telNum[i]);
}
}
int main(){
in ();
qsort(telNum,n,
sizeof ( char ) * 9 ,cmp);
print();
return 0 ;
}

你可能感兴趣的:(poj)