Advertisement
ashmelev

Set + Map - B09

Nov 24th, 2020
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. pair<string, string> split(string s) {
  11.     // разбиваем строку на сервер и запрос
  12.     int p = (int)(find(s.begin() + 7, s.end(), '/') - s.begin());
  13.     string s1 = s.substr(0, p);
  14.     string s2 = s.substr(p);
  15.     return make_pair(s1, s2);
  16. }
  17.  
  18. int main() {
  19.     map<string, set<string> > m1;
  20.  
  21.     int n;
  22.     cin >> n;
  23.     for (int i = 0; i < n; i++) {
  24.         string s;
  25.         cin >> s;
  26.         auto t = split(s);
  27.         m1[t.first].insert(t.second);
  28.     }
  29.  
  30.     map<set<string>, vector<string> > m2;
  31.     for (auto x: m1)
  32.         m2[x.second].push_back(x.first);
  33.  
  34.     vector<vector<string> > v;
  35.     for (auto x: m2)
  36.         if (x.second.size() > 1)
  37.             v.push_back(x.second);
  38.  
  39.     cout << v.size() << "\n";
  40.     for (auto x : v) {
  41.         for (auto y : x)
  42.             cout << y << ' ';
  43.         cout << "\n";
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement