Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <set>
  5. #include <vector>
  6. using namespace std;
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.     map<string, vector<string>> dict;
  11.     for (int i = 0; i <= n; i++) {
  12.         string s;
  13.         getline(cin, s);
  14.         string tmp = "";
  15.         vector<string> tmp1(0);
  16.         int x = 0, y = 0;
  17.         for (int j = 0; j < s.length(); j++) {
  18.             if (s[j] == '-') {
  19.                 y = j - 2;
  20.                 tmp = s.substr(x, y + 1-x);
  21.                 x = j + 2;
  22.             }
  23.             else if (s[j] == ',') {
  24.                 y = j - 1;
  25.                 tmp1.push_back(s.substr(x, y + 1-x));
  26.                 x = j + 2;
  27.             }
  28.             else if (j == s.length() - 1) {
  29.                 tmp1.push_back(s.substr(x, j + 1 - x));
  30.             }
  31.         }
  32.         dict[tmp] = tmp1;
  33.     }
  34.     set<string> xin;
  35.     for (auto now : dict) {
  36.         for (auto now1 : now.second) {
  37.             xin.insert(now1);
  38.         }
  39.     }
  40.     cout << xin.size() << endl;
  41.     for (auto now : xin) {
  42.         vector<string> tmp(0);
  43.         for (auto now1 : dict) {
  44.             for (auto now2 : now1.second) {
  45.                 if (now == now2) {
  46.                     tmp.push_back(now1.first);
  47.                 }
  48.             }
  49.         }
  50.         cout << now<<" - ";
  51.         for (auto now3 : tmp) {
  52.             if (now3 == tmp[tmp.size() - 1]) cout << now3;
  53.             else cout << now3 << ", ";
  54.         }
  55.         cout << endl;
  56.     }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement