Sets-STL

Sort by

recency

|

331 Discussions

|

  • + 0 comments

    Here is Sets-STL problem solution in C++ - https://programmingoneonone.com/hackerrank-sets-stl-solution-in-cpp.html

  • + 0 comments

    //M.Kohaku

    include

    using namespace std;

    int main(){ sets; int n; cin >> n; for(int i=0;i p; cin >> p.first >> p.second; int x = p.first; int y = p.second; if(x==1){ s.insert(y); } else if(x==2){ s.erase(y); } else if(x==3){ if(s.count(y)) cout << "Yes" << endl; else cout << "No" << endl; } } }

  • + 0 comments

    My solution:

    int main() {
        set<int> values;
        int queries, qType, qVal;
        cin >> queries; 
        while(queries) {
            cin >> qType >> qVal;
            switch (qType) {
                case 1:
                    values.insert(qVal);
                    break;
                case 2:
                    values.erase(qVal);
                    break;
                case 3:
                    if(values.find(qVal) != values.end())
                        cout << "Yes\n";
                    else
                        cout << "No\n";
                    break;
            }
            queries--;
        }
        return 0;
    }
    
  • + 0 comments

    My C++ code

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <set>
    using namespace std;
    
    
    int main() {
        int query{0};
        std::cin>>query;
        std::set<int> set_x;
        for(int i = 0;i < query;i++) {
            int x(0),y(0);
            std::cin>>x;
            std::cin>>y;
            if(x == 1) {
                set_x.insert(y);
            }else if(x == 2) {
                set_x.erase(y);
            }else {
                if(set_x.find(y) != set_x.end()) {
                    std::cout<<"Yes\n";
                }else {
                    std::cout<<"No\n";
                }
            }
        }
        return 0;
    }
    
  • + 0 comments
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        set<int> s;
        int Q;
        cin >> Q;
        for (int i = 0; i < Q; i++) {
          pair<int, int> query;
          cin >> query.first >> query.second;
          int x = query.first;
          int y = query.second;
          if (x == 1) {
            s.insert(y);
          } else if (x == 2) {
            s.erase(y);
          } else if (x == 3) {
            set<int>::iterator it = s.find(y);
            it == s.end() ? cout << "No\n" : cout << "Yes\n";
          }
        }
        return 0;
    }