//开阔思维,怎么简单怎么来
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
// freopen("input.txt","r",stdin);
char words[101][10],str[10],str1[10];
int i,j,length1,length2,s = 0;
while(1){
scanf("%s",words[s]);
if(strcmp(words[s++],"XXXXXX") == 0) break;
}
/*下便便是对输入的单词按字典排序,其实就是选择排序,因为对于C语言中qsort
中对二维字符串排序比较难理解,干脆自己写一个。*/
for(i = 0;i < s - 2; i++)
for(j = i + 1;j < s - 1; j++)
if(strcmp(words[i],words[j]) > 0){
strcpy(str,words[i]);
strcpy(words[i],words[j]);
strcpy(words[j],str);
}
while(scanf("%s",str) != EOF && strcmp(str,"XXXXXX") != 0){ //输入形式注意了
int flag = 1;
for(i = 0;i < s - 1; i++){
length1 = strlen(str);
length2 = strlen(words[i]);
strcpy(str1,words[i]);
sort(str,str + length1);
sort(str1,str1 + length2);
if(strcmp(str1,str) == 0){
printf("%s\n",words[i]);
flag = 0;
}
}
if(flag)
printf("NOT A VALID WORD\n");
printf("******\n");
}
return 0;
}
06-01