HDU1113 字符串处理
题意:给定一个字典,给定一些询问,对于每个询问,在字典中找出与之匹配的单词(匹配的规则:两者的排序之后结果是相同的)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<string> 3 #include<map> 4 #include<iostream> 5 #include<algorithm> 6 using namespace std; 7 map<string,string>mp; 8 string my_end="XXXXXX"; 9 int main(){ 10 string s,temp; 11 while( cin>>s && s!=my_end ){ 12 temp=s; 13 sort( temp.begin(),temp.end() ); 14 mp[ s ]=temp; 15 } 16 while( cin>>s && s!=my_end ){ 17 temp=s; 18 sort( temp.begin(),temp.end() ); 19 int flag=0; 20 for( map<string,string>::iterator it =mp.begin();it!=mp.end();it++ ){ 21 if( it->second==temp ){ 22 flag=1; 23 cout<<it->first<<endl; 24 } 25 } 26 if(!flag) 27 cout<<"NOT A VALID WORD"<<endl; 28 cout<<"******"<<endl; 29 } 30 return 0; 31 }
stl很强大!!!
keep moving...