标签:输出 cpp ++i out prefix put code iterator output
#include<iostream> #include<string> #include<list> #include<map> #include<utility> #include<algorithm> using namespace std; map<string,int> outputMap; void ergodic(string prefix, string str){ if(str==""){ outputMap.insert(pair<string,int>(prefix,0)); }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; outputMap.clear(); ergodic("",str); for(map<string,int>::iterator iter=outputMap.begin(); iter!=outputMap.end(); ++iter){ if(find(inputList.begin(),inputList.end(),iter->first)!=inputList.end()){ cout<<iter->first<<endl; isUnscramble=true; } } if(!isUnscramble){ cout<<"NOT A VALID WORD"<<endl; } cout<<"******"<<endl; } return 0; }
POJ-1318(list.sort()输出不为字典序,map才是按字典序排列)
标签:输出 cpp ++i out prefix put code iterator output
原文地址:http://www.cnblogs.com/jhcelue/p/6785515.html