#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
*/
【编程珠玑】兄弟单词(侧边栏)
最新推荐文章于 2024-11-30 21:41:55 发布
