Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.   map <string, set <string>> voc;
  10.   string s, en, lt;
  11.   int n, k = 0;
  12.   cin >> n;
  13.   for (int i = 0; i < n; i++) {
  14.       getline(cin, s);
  15.       k = s.find("-");
  16.       en = s.substr(0, k - 2);
  17.       s = s.substr(k + 2) + ",";
  18.       k = -1;
  19.       while (s.find(",", k + 1) != -1) {
  20.           lt = s.substr(k + 1, s.find(",", k + 1) - k - 1);
  21.           if (voc.find(lt) != voc.end()) {
  22.               voc.insert(pair <string, set <string>> (lt, {en}));
  23.           }
  24.           else {
  25.               voc[lt].insert(en);
  26.           }
  27.           if (s.size() - 1 != s.find(",", k + 1)){
  28.               k = s.find(",", k + 1);
  29.           }
  30.           else {
  31.               break;
  32.           }
  33.       }
  34.   }
  35.   for (auto a : voc) {
  36.       cout << a.first << " - ";
  37.       for (auto b : a.second) {
  38.           cout << b;
  39.           if (b == *a.second.rbegin()) {
  40.               break;
  41.           }
  42.           cout << ",";
  43.       }
  44.       cout << endl;
  45.   }
  46.   return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement