Advertisement
CyberN00b

Untitled

Dec 25th, 2022
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int a;
  7.     cin >> a;
  8.     vector<string> input;
  9.     for (int i = 0; i < a; ++i) {
  10.         string tmp;
  11.         cin >> tmp;
  12.         input.push_back(tmp);
  13.     }
  14.     unordered_map<bitset<26>, vector<string> > m;
  15.     for (auto& x : input) {
  16.         bitset<26> b;
  17.         for (auto& y : x) {
  18.             b[y - 'a'] = 1;
  19.         }
  20.         if (m.contains(b)) {
  21.             m[b].push_back(x);
  22.         } else {
  23.             m[b] = {x};
  24.         }
  25.     }
  26.     for (auto& x : m) {
  27.         for (auto &y: x.second)
  28.             cout << y << ' ';
  29.         cout << endl;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement