ACM (TJU) : 1903


#include
#include

struct node {
char ch [10];
int alpha [28];
} a [105], temp;

void reset ()
{
for ( int i = 0; i < 105; i++ ) { strcpy (a[i].ch, ""); for ( int j = 0; j < 28; j++ ) a [i].alpha [j] = 0; } } void find ( int alpha1 [28], int index ) { bool track = true; for ( int i = 0; i < index; i++ ) { bool flag = true; for ( int j = 0; j < 28; j++ ) { if ( a [i].alpha [j] != alpha1 [j] ) { flag = false; break; } } if ( flag ) { printf ("%s\n", a [i].ch); track = false; } } if ( track ) printf ("NOT A VALID WORD\n"); printf ("******\n"); } int main () { reset (); char dictionary [10]; int index = 0; /* input */ while ( scanf ("%s", dictionary) ) { if ( strcmp ("XXXXXX", dictionary) == 0 ) break; strcpy (a [index].ch, dictionary); for ( int i = 0; i < strlen (dictionary); i++ ) a [index].alpha [dictionary [i] - 97]++; index++; } /* Sort alphabetically */ for ( int i = 0; i < index; i++ ) { for ( int j = i + 1; j < index; j++ ) { if ( strcmp ( a[i].ch, a [j].ch) > 0 ) {
temp = a [i];
a [i] = a [j];
a [j] = temp;
}
}
}

char input [10];

while ( scanf (“%s”, input) ) {

if ( strcmp (“XXXXXX”, input) == 0 )
break;

int alpha2 [28] = {0};

for ( int i = 0; i < strlen (input); i++ ) alpha2 [input [i] - 97]++; find (alpha2, index); } return 0; } [/sourcecode]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s