PKU 1318 Word Amalgamation

http://poj.org/problem?id=1318
最初に辞書文字列が与えられた後に、入力文字列が与えられる。
各入力文字列について、同じ文字が同じ個数出現している辞書文字列を全て出力するというような問題。

mapとsortとsetを使って書くだけ。

map<string,set<string> > dict;

main(){
  string in;
  while(cin>>in){
    if(in=="XXXXXX")break;
    string sorted=in;
    sort(ALL(sorted));
    dict[sorted].insert(in);
  }
  while(cin>>in){
    if(in=="XXXXXX")break;
    bool ok=false;
    
    string sorted=in;
    sort(ALL(sorted));
    FOR(siter,dict[sorted]){
      cout<<*siter<<endl;
      ok=true;
    }
    if(!ok)cout<<"NOT A VALID WORD"<<endl;
    cout<<"******"<<endl;
  }
}