Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <map>
  4. #include <set>
  5. #include <algorithm>
  6. #include <string>
  7.  
  8. using namespace std;
  9. void add(set<set<string>>& m, int& k){
  10.     string str;
  11.     int mycount;
  12.     int flag = 0;
  13.     set<string> s;
  14.     for (int i = 0; i < 2; ++i){
  15.         cin >> str;
  16.         s.insert(str);
  17.     }
  18.     mycount = count(m.begin(), m.end(), s);
  19.     if (mycount == 0){
  20.         m.insert(s);
  21.     }
  22.  
  23. }
  24.  
  25.  
  26. void count(const vector<set<string>>& m){
  27.     string str;
  28.     int mycount = 0;
  29.     int sum = 0;
  30.     cin >> str;
  31.     for(auto k : m){
  32.         mycount = count(k.begin(), k.end(), str);
  33.         sum += mycount;
  34.     }
  35.  
  36.     cout << sum << endl;
  37.  
  38. }
  39.  
  40.  
  41. void check(vector<set<string>>& m){
  42.     string str;
  43.     int flag = 0;
  44.     int mycount;
  45.     set<string> s;
  46.     for (int i = 0; i < 2; ++i){
  47.         cin >> str;
  48.         s.insert(str);
  49.     }
  50.     mycount = count(m.begin(), m.end(), s);
  51.     if (mycount == 0){
  52.         cout << "NO" << endl;
  53.     }
  54.     else{
  55.         cout << "YES" << endl;
  56.     }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. int main(){
  64.     vector<set<string>> m;
  65.     int Q;
  66.     int k = 0;
  67.     string str;
  68.     cin >> Q;
  69.     for(int i = 0; i < Q; ++i){
  70.         cin >> str;
  71.         if (str == "ADD"){
  72.             add(m, k);
  73.  
  74.         }
  75.  
  76.         if (str == "COUNT"){
  77.             count(m);
  78.  
  79.         }
  80.  
  81.         if (str == "CHECK"){
  82.             check(m);
  83.         }
  84.  
  85.     }
  86.  
  87.     return 0;
  88.  
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement