class Solution {
public:
/**
* @param strs: A list of strings
* @return: A list of strings
*/
vector<string> anagrams(vector<string> &strs) {
// write your code here
vector<string>::iterator beg=strs.begin(),iter,iter1,
end=strs.end();
vector<string> result;
set<int> record; int flag;
for(iter=beg;iter!=end;iter++){
if(!record.count(iter-beg)){
flag=0; string s1=*iter; std::sort(s1.begin(),s1.end());
for(iter1=iter+1;iter1!=end;iter1++){
string s2=*iter1;
std::sort(s2.begin(),s2.end());
if(s1==s2) {
++flag;
if(flag==1) { result.push_back(*iter);result.push_back(*iter1);}
else result.push_back(*iter1);
record.insert(iter1-beg);
}
}
}
}
return result;
}
};