AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving ::Sorting/Searching
// 156 - Ananagrams
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
using namespace std;
char word[5000][50], sorted[5000][50];
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 main(void)
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int i, j, len, n=0;
while(cin>>word[n] && word[n][0]!='#')
n++;
qsort(word, n, sizeof(word[0]), cmp_string);
/*
for(i=0; i<n; i++)
cout << word[i] << " ";
cout << endl;
*/
for(i=0; i<n; i++)
{
len = strlen(word[i]);
for(j=0; j<len; j++)
sorted[i][j] = tolower(word[i][j]);
qsort(sorted[i], strlen(sorted[i]), sizeof(char), cmp_char);
}
/*
for(i=0; i<n; i++)
cout << sorted[i] << " ";
cout << endl;
*/
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(i == j)
continue;
if(strcmp(sorted[i], sorted[j]) == 0)
break;
}
if(j == n)
cout << word[i] << endl;
}
return 0;
}