【编程珠玑】兄弟单词(侧边栏)

#define WORDMAX 100
struct my
{
	char word[256];
	char sig[256];
} wo[WORDMAX];
char oldsig[256];
bool cmp(my a, my b)
{
	if (strcmp(a.sig, b.sig) < 0) return true;
	return false;
}
int main()
{
	/* sign */
	int index = 0;
	while (scanf("%s", wo[index].word) != EOF) {
		strcpy(wo[index].sig, wo[index].word);
		sort(wo[index].sig, wo[index].sig + strlen(wo[index].sig));		
		++index;
	}

	/* sort */
	sort(wo, wo + index, cmp);

	/* squash */
	strcpy(oldsig, "");
	int i;
	for (i = 0; i < index; ++i) {
		if (strcmp(oldsig, wo[i].sig) != 0 && i) {
			printf("\n");
		}
		strcpy(oldsig, wo[i].sig);
		printf("%s ", wo[i].word);
	}
	printf("\n");
	return 0;
}
/*
pans
pots
opt
snap
stop
tops
*/

你可能感兴趣的:(【编程珠玑】兄弟单词(侧边栏))