Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <set>
  6. #include <vector>
  7. #include <algorithm>
  8.  
  9. using namespace std;
  10.  
  11. int main() {
  12.  
  13.     map<string, set<string>> words;
  14.     map<string, int> kol;
  15.  
  16.     int q;
  17.     cin >> q;
  18.  
  19.     for (int i = 0; i < q; i++) {
  20.  
  21.         string comand;
  22.         cin >> comand;
  23.  
  24.         if (comand == "ADD") {
  25.  
  26.             string s1, s2;
  27.             cin >> s1 >> s2;
  28.  
  29.             words[s1].insert(s2);
  30.             words[s2].insert(s1);
  31.             kol[s1]++;
  32.             kol[s2]++;
  33.  
  34.         }
  35.         else if (comand == "COUNT") {
  36.  
  37.             string s;
  38.             cin >> s;
  39.  
  40.             cout << kol[s] << endl;
  41.             //cout << words[s].size() << endl;
  42.  
  43.         }
  44.         else if (comand == "CHECK") {
  45.  
  46.             string s1, s2;
  47.             cin >> s1 >> s2;
  48.  
  49.             if (words[s1].count(s2) == 0) {
  50.                 cout << "NO" << endl;
  51.             }
  52.             else {
  53.                 cout << "YES" << endl;
  54.             }
  55.  
  56.         }
  57.  
  58.     }
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement