fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7.  
  8.  
  9. vector<vector<string>> res;
  10. unordered_map<string, int> mp;
  11.  
  12. vector<string> arr= {
  13. "1$0$1$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$1$0$0$0$0$0$0$",
  14. " 0$0$0$1$0$0$1$0$0$0$0$0$0$0$1$0$0$0$0$0$0$0$0$0$0$0$",
  15. " 1$0$1$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$1$0$0$0$0$0$0$",
  16. " 0$0$0$1$0$0$1$0$0$0$0$0$0$0$1$0$0$0$0$0$0$0$0$0$0$0$",
  17. " 1$0$1$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$1$0$0$0$0$0$0$"
  18. };
  19.  
  20.  
  21. for (int i = 0; i < arr.size(); i++) {
  22. string key = arr[i];
  23.  
  24. // If key is not present in the hash map, add
  25. // an empty group (vector) in the result and
  26. // store the index of the group in hash map
  27. if (mp.find(key) == mp.end()) {
  28. mp[key] = res.size();
  29. res.push_back({});
  30. }
  31.  
  32. // Insert the string in its correct group
  33. res[mp[key]].push_back(arr[i]);
  34.  
  35.  
  36. //cout<<res;
  37. }
  38.  
  39. for(int i = 0; i < res.size(); i++) {
  40. for(int j = 0; j < res[i].size(); j++)
  41. cout << res[i][j] << " ";
  42.  
  43. // cout<<res[i][0];
  44. cout << "\n";
  45. }
  46.  
  47. //cout<<res;
  48. //return res;
  49. return 0;
  50. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1$0$1$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$1$0$0$0$0$0$0$ 
 0$0$0$1$0$0$1$0$0$0$0$0$0$0$1$0$0$0$0$0$0$0$0$0$0$0$  0$0$0$1$0$0$1$0$0$0$0$0$0$0$1$0$0$0$0$0$0$0$0$0$0$0$ 
 1$0$1$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$1$0$0$0$0$0$0$  1$0$1$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$1$0$0$0$0$0$0$