Sets-STL

Sort by

recency

|

334 Discussions

|

  • + 0 comments

    Here is my solution!

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <set>
    using namespace std;
    
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int num_queries, query_type, query;
        set<int> ints;
        cin >> num_queries;
        for (int i = 0; i < num_queries; i++) {
            cin >> query_type >> query;
            if (query_type == 1) {
                ints.insert(query);
            } else if (query_type == 2) {
                ints.erase(query);
            } else {
                set<int>::iterator itr = ints.find(query);
                if (itr == ints.end()) {
                    cout << "No\n";
                } else {
                    cout << "Yes\n";
                }
            }
        }
        return 0;
    }
    
  • + 0 comments
    #include <iostream>
    #include <set>
    
    using namespace std;
    
    int main()
    {
        int q;
        cin >> q;
    
        set<int> set;
    
        while (q > 0)
        {
            int y, x;
            cin >> y >> x;
    
            switch (y)
            {
            case 1:
            {
                set.insert(x);
                break;
            }
            case 2:
            {
                set.erase(x);
                break;
            }
            default:
                if (set.end() != set.find(x))
                    cout << "Yes" << endl;
                else
                    cout << "No" << endl;
                break;
            }
    
            q--;
        }
    }
    
  • + 0 comments

    int main() { set s; int q; int a; int y; cin>>q; while(q>0){ cin>>a; if(a==1){ cin>>y;

            s.insert(y);
        }
        else if(a==2){
            cin>>y;
            auto it=s.find(y);
            if(it!=s.end()){
                s.erase(*it);
            }
            else{
                continue;
            }
        }
        else if(a==3){
            cin>>y;
            auto itr=s.find(y);
            if(itr!=s.end()){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
    
        }
        q--;
    }  
    return 0;
    

    }

  • + 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; } } }