#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <algorithm>
char word[25],words[1500][25],wordsSorted[1500][25],ananagram[1000][25];
int cmp(const void*a,const void*b)
{
return strcmp((char *)a,(char *)b);
}
int main()
{
int n=0,count=0,flag=0;
while(scanf("%s",words[n]))
{
if(words[n][0]=='#') break;
int i;
for(i=0;i<strlen(words[n]);i++)
{
wordsSorted[n][i]=tolower(words[n][i]);
}
wordsSorted[n][i]='\0';
std::sort(wordsSorted[n],wordsSorted[n]+strlen(wordsSorted[n]));
n++;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i!=j)
{
if(!strcmp(wordsSorted[i],wordsSorted[j]))
{
flag=1;
}
}
}
if(flag==0)
{
strcpy(ananagram[count],words[i]);
count++;
}
flag=0;
}
qsort(ananagram,count,sizeof(ananagram[0]),cmp);
for(int i=0;i<count;i++)
printf("%s\n",ananagram[i]);
return 0;
}
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=92