/*
* 解题思路:
* 经典的字母重排问题,忽略大小写的比较,如果输入没有该单词对应的其他重排单词,则原单词输出
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define A 1000
char s1[ A ][ A ],s2[ A ][ A ];
char s3[ A ][ A ];
int p,q;
int cmp_char( const void *_a , const void *_b )
{
char *a = (char * )_a;
char *b = (char* )_b;
return *a-*b;
}
int cmp_string( const void *_a , const void *_b )
{
char * a = (char *)_a;
char *b = (char * )_b;
return strcmp( a , b );
}
int search( int x )
{
int i,j;
for( i=0;i<p;i++ )
{
if( i == x ) continue;
for( j=0;j<strlen( s2[x] );j++ )
if( s2[ x ][ j ] != s2[ i ][ j ] )
break;
if( j == strlen( s2[ x ]) && j == strlen( s2[ i ]) ) return 1;
}
return 0;
}
int main( )
{
int i,j;
int x,q;
char c;
p = 0;
while( scanf("%s",&s1[ p ] ) && s1[ p ][ 0 ] != '#' ) p++;
for( i=0;i<p;i++ )
{
for( j=0;j<strlen( s1[ i ] ) ;j++ )
s2[ i ][ j ] = tolower( s1[ i ][ j ] );
s2[ i ][ j ] = '\0';
}
for( i=0;i<p;i++ )
qsort( s2[ i ] , strlen( s2[ i ] ) , sizeof(char ) , cmp_char );
q = 0;
for( i=0;i<p;i++ )
{
x = search( i );
if( x == 0 )
strcpy( s3[ q++ ] , s1[ i ] );
}
qsort( s3 , q , sizeof( s3[ 0 ]) , cmp_string );
for( i=0;i<q;i++)
printf("%s\n",s3[ i ] );
return 0;
}