Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<map>
- #include<string>
- #include<set>
- using namespace std;
- set<map<string, string>> add(string word1, string word2, set<map<string, string>>& s) {
- s.insert({ word1, word2 });
- return s;
- }
- int count_synonyms(string word, const set<map<string, string>>& s) {
- int counts = 0;
- for (const auto& x1 : s)
- for (const auto& x2 : x1)
- if (word == x2.first || word == x2.second)
- ++counts;
- return counts;
- }
- bool check(string word1, string word2, const set<map<string, string>>& s) {
- for (const auto& x1 : s)
- for (const auto& x2 : x1)
- if ((word1 == x2.first && word2 == x2.second) || (word2 == x2.first && word1 == x2.second))
- return true;
- else
- return false;
- }
- int main()
- {
- set<map<string, string>> synonyms;
- int q = 0;
- cin >> q;
- for (int i = 0; i < q; ++i)
- {
- string operation = "";
- cin >> operation;
- if (operation == "ADD") {
- string word1, word2;
- cin >> word1 >> word2;
- add(word1, word2, synonyms);
- }
- if (operation == "COUNT") {
- string word;
- cin >> word;
- cout << count_synonyms(word, synonyms);
- }
- if (operation == "CHECK") {
- string word1, word2;
- cin >> word1 >> word2;
- if (check(word1, word2, synonyms))
- cout << "YES";
- else
- cout << "NO";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement