#include<iostream>
#include<list>
#include<algorithm>
#include<string>
using namespace std;
list<string> dic; //字典单词
list<string>dicf; //对每个单词排序
int main()
{
string s;
while(cin>>s) //输入字典
{
if(s == "XXXXXX")
break;
dic.push_back(s);
}
//字典排序
list<string>::iterator ite = dic.begin();
while(ite != dic.end())
{
list<string>::iterator ite2 = ++ite;
--ite;
while(ite2 != dic.end())
{
if((*ite).compare(*ite2)>0)
{
string pNode = *ite;
*ite = *ite2;
*ite2 = pNode;
}
++ite2;
}
++ite;
}
//另一个链表装字典,并把原来字典的单词打乱
ite = dic.begin();
while(ite != dic.end())
{
string d = *ite;
dicf.push_back(d);
sort((*ite).begin(),(*ite).end());
++ite;
}
while(cin>>s)
{
bool flag = false;
if(s =="XXXXXX")
break;
sort(s.begin(),s.end());
ite = dic.begin();
list<string>::iterator ite2 = dicf.begin();
while(ite != dic.end())
{
if(s.compare(*ite) ==0)
{
cout<<*ite2<<endl;
flag = true;
}
++ite;
++ite2;
}
if(flag == false)
cout<<"NOT A VALID WORD"<<endl;
cout<<"******"<<endl;
}
return 0;
}
ZOJ 1181 关于list的题
最新推荐文章于 2024-08-13 13:32:44 发布