题意:把每个单词全部转化成小写字母,对每个单词,看它的字母重排后得到的单词在所有输入的单词中是否出现过,若没有出现,就输出原单词。所有要输出的单词按字典序排列输出。
水题一道 结构体排序自己写一个 计算的时候注意标记序号和是否出现 否者排序了后没法输出
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;
const int maxn =1005;
int T = 0;
struct Words
{
char s[25];
int visit,len,n;
}st[1005],words[1005];
int cmp(Words a, Words b)
{
int i;
for(i = 0; a.s[i]!='\0' && b.s[i]!='\0'; i++)
if(a.s[i] < b.s[i])return 1;
else if(a.s[i] > b.s[i])return 0;
if(a.s[i]=='\0')return 1;
else return 0;
}
void Solve()
{
int i,j,k;
for(i = 0; i < T-1; i++)
{
char a[25], b[25];
strcpy(a,st[i].s);
sort(a,a+strlen(a));
for(j = i+1; j < T; j++)
{
strcpy(b,st[j].s);
sort(b,b+strlen(b));
if(strcmp(a,b) == 0)
st[i].visit = st[j].visit= 0;
}
}
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
char str[100];
while(gets(str)!=NULL)
{
if(str[0] == '#')
{
Solve();
sort(words,words+T,cmp);
for(int i = 0; i < T; i++)
if(st[words[i].n].visit)puts(words[i].s);
T = 0;
}
else
{
int str_len = strlen(str);
for(int i = 0; i < str_len; i++)//把单词全部存到st中
{
if(!isalpha(str[i]))continue;
int t = 0;
while(isalpha(str[i]))
{
words[T].s[t] = str[i];
st[T].s[t++] = tolower(str[i++]);
}
words[T].s[t] = st[T].s[t] = '\0';
st[T].len = strlen(st[T].s);
st[T].visit = 1;
words[T].n = st[T].n = T;
T++;
}
}
}
return 0;
}