Advertisement
dimon-torchila

Untitled

Jan 31st, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include<iostream>
  2. #include<map>
  3. #include<string>
  4. #include<set>
  5.  
  6. using namespace std;
  7.  
  8. set<map<string, string>> add(string word1, string word2, set<map<string, string>>& s) {
  9.     s.insert({ word1, word2 });
  10.     return s;
  11. }
  12.  
  13. int count_synonyms(string word, const set<map<string, string>>& s) {
  14.     int counts = 0;
  15.     for (const auto& x1 : s)
  16.         for (const auto& x2 : x1)
  17.             if (word == x2.first || word == x2.second)
  18.                 ++counts;
  19.     return counts;
  20. }
  21.  
  22. bool check(string word1, string word2, const set<map<string, string>>& s) {
  23.     for (const auto& x1 : s)
  24.         for (const auto& x2 : x1)
  25.             if ((word1 == x2.first && word2 == x2.second) || (word2 == x2.first && word1 == x2.second))
  26.                 return true;
  27.             else
  28.                 return false;
  29. }
  30.  
  31. int main()
  32. {
  33.     set<map<string, string>> synonyms;
  34.     int q = 0;
  35.     cin >> q;
  36.     for (int i = 0; i < q; ++i)
  37.     {
  38.         string operation = "";
  39.         cin >> operation;
  40.         if (operation == "ADD") {
  41.             string word1, word2;
  42.             cin >> word1 >> word2;
  43.             add(word1, word2, synonyms);
  44.         }
  45.         if (operation == "COUNT") {
  46.             string word;
  47.             cin >> word;
  48.             cout << count_synonyms(word, synonyms);
  49.         }
  50.         if (operation == "CHECK") {
  51.             string word1, word2;
  52.             cin >> word1 >> word2;
  53.             if (check(word1, word2, synonyms))
  54.                 cout << "YES";
  55.             else
  56.                 cout << "NO";
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement