fork download
  1. #include <iostream>
  2. #include<map>
  3. #include<vector>
  4. using namespace std;
  5. map<string , vector<string>> mp;
  6.  
  7. string encode(string s)
  8. {
  9. int even[26]={0};
  10. int odd[26]={0};
  11.  
  12. string encoding="";
  13.  
  14. for(int i =0 ;i < s.length(); i++)
  15. {
  16. even[s[i] - 'a']++;
  17. }
  18.  
  19. for(int i =0 ;i< 26 ;i++)
  20. {
  21. encoding+=to_string(even[i]);
  22. encoding+="-";
  23. }
  24.  
  25. mp[encoding].push_back(s);
  26. return encoding;
  27. }
  28.  
  29. int main() {
  30.  
  31. vector<string> words ={"plea", "pale", "test", "pela"};
  32. string x = "pale";
  33. x= encode(x);
  34.  
  35. for(auto it: words)
  36. encode(it);
  37.  
  38.  
  39. /* for(auto it : mp)
  40. {
  41. cout << it.first << " =";
  42. for(auto it1 : it.second)
  43. cout << it1 << " ";
  44.  
  45. cout << endl;
  46. }*/
  47. vector<string> res= mp[x];
  48.  
  49. for(auto it: res)
  50. cout << it << endl;
  51.  
  52. // your code goes here
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
pale
plea
pale
pela