fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <set>
  5. #include <map>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. vector<set<string>> bar(vector<string> strs){
  10. map<string,set<string>> m;
  11. for(auto x: strs){
  12. auto sorted = x;
  13. sort(sorted.begin(), sorted.end());
  14. set<string>& currentset = m[sorted];
  15. currentset.insert(x);
  16. };
  17.  
  18. vector<set<string>> result;
  19. for(auto itr = m.begin(); itr != m.end(); itr++){
  20. result.push_back(itr->second);
  21. }
  22.  
  23. return result;
  24. }
  25.  
  26. int main()
  27. {
  28. vector<string> strs = {string("123"), string("321"), string("555")};
  29. auto res = bar(strs);
  30. for(auto s: res){
  31. for(auto str: s){
  32. cout << str << " ";
  33. }
  34. cout << endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
123 321 
555