#include <iostream>
using namespace std;
#include <bits/stdc++.h>
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs)
{
unordered_map<string ,vector<string> >m;
for(int i=0;i<strs.size();i++)
{
string temp=strs[i];
sort(temp.begin(),temp.end());
if(m.find(temp)!=m.end())//找到了
{
auto it=m.find(temp);
it->second.push_back(strs[i]);
}
else //没找到
{
vector<string> l;
l.push_back(strs[i]);
m.insert( pair< string,vector<string> >(temp,l));
}
}
vector< vector<string> >result;
for(auto it= m.begin(); it!=m.end();it++)
result.push_back(it->second);
return result;
}
};
int main()
{
string a[6]={"eat", "tea", "tan", "ate", "nat", "bat"};
vector<string>v(a,a+6);
Solution l;
vector< vector<int> >result=l.groupAnagrams(v);
}