Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<map>
- #include<set>
- using namespace std;
- void ADDSYNONYMS(map<string, set<string>>& synonyms, const string& first_word, const string& second_word)
- {
- synonyms[second_word].insert(first_word);
- synonyms[first_word].insert(second_word);
- }
- size_t GETSYNONYMCOUNT(map<string, set<string>>& synonyms, const string& first_word)
- {
- return synonyms[first_word].size();
- }
- bool ARESYNONYMS(map<string, set<string>>& synonyms, const string& first_word, const string& second_word)
- {
- return synonyms[first_word].count(second_word) == 1;
- }
- int main()
- {
- int q;
- cin >> q;
- map<string, set<string>> synonyms;
- for (int i = 0; i < q; i++)
- {
- string operation_code;
- cin >> operation_code;
- if (operation_code == "ADD")
- {
- string first_word, second_word;
- cin >> first_word >> second_word;
- ADDSYNONYMS(synonyms, first_word, second_word);
- /*synonyms[second_word].insert(first_word);
- synonyms[first_word].insert(second_word);*/
- }
- else if (operation_code == "COUNT")
- {
- string word;
- cin >> word;
- cout << GETSYNONYMCOUNT(synonyms, word) << endl;
- /*cout << synonyms[word].size()<<endl;*/
- }
- else if (operation_code == "CHECK")
- {
- string first_word, second_word;
- cin >> first_word >> second_word;
- if (ARESYNONYMS(synonyms, first_word, second_word))
- {
- cout << "YES" << endl;
- }
- else
- {
- cout << "NO" << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement