Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 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. #include <chrono>
  9.  
  10. using namespace std;
  11. using namespace std::chrono;
  12.  
  13. int main() {
  14.  
  15.     map<string, set<string>> words;
  16.  
  17.     int q;
  18.     cin >> q;
  19.  
  20.     for (int i = 0; i < q; i++) {
  21.  
  22.         string comand;
  23.         cin >> comand;
  24.  
  25.         if (comand == "ADD") {
  26.             auto start = steady_clock::now();
  27.  
  28.             string s1, s2;
  29.             cin >> s1 >> s2;
  30.  
  31.             words[s1].insert(s2);
  32.             words[s2].insert(s1);
  33.  
  34.             auto finish = steady_clock::now();
  35.             cout << "ADD" << duration_cast<milliseconds>(finish - start).count() << "ms" << endl;
  36.  
  37.         }
  38.         else if (comand == "COUNT") {
  39.  
  40.             auto start = steady_clock::now();
  41.  
  42.             string s;
  43.             cin >> s;
  44.  
  45.             cout << words[s].size() << endl;
  46.  
  47.             auto finish = steady_clock::now();
  48.             cout << "COUNT" << duration_cast<milliseconds>(finish - start).count() << "ms" << endl;
  49.  
  50.         }
  51.         else if (comand == "CHECK") {
  52.  
  53.             auto start = steady_clock::now();
  54.  
  55.             string s1, s2;
  56.             cin >> s1 >> s2;
  57.  
  58.             if (words[s1].count(s2) == 0) {
  59.                 cout << "NO" << endl;
  60.             }
  61.             else {
  62.                 cout << "YES" << endl;
  63.             }
  64.  
  65.             auto finish = steady_clock::now();
  66.             cout << "CHECK" << duration_cast<milliseconds>(finish - start).count() << "ms" << endl;
  67.  
  68.         }
  69.  
  70.     }
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement