#include<iostream> #include<string> #include<list> #include<algorithm> using namespace std; list<string> outputList; void ergodic(string prefix, string str){ if(str==""){ //cout<<prefix<<endl; outputList.push_back(prefix); }else{ for(int i=0;i<str.length();i++){ ergodic(prefix+str[i],str.substr(0,i)+str.substr(i+1,str.length())); } } } int main(int argc, char *argv[]){ string str; list<string> inputList; while(cin>>str,str!="XXXXXX"){ inputList.push_back(str); } while(cin>>str,str!="XXXXXX"){ bool isUnscramble=false; outputList.clear(); ergodic("",str); unique(outputList.begin(),outputList.end()); //sort(outputList.begin(),outputList.end(),less<string>()); outputList.sort(); for(list<string>::iterator iter=outputList.begin(); iter!=outputList.end(); ++iter){ if(find(inputList.begin(),inputList.end(),*iter)!=inputList.end()){ cout<<*iter<<endl; isUnscramble=true; } } if(!isUnscramble){ cout<<"NOT A VALID WORD"<<endl; } cout<<"******"<<endl; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-13 16:04:11