Sets-STL

Sort by

recency

|

325 Discussions

|

  • + 0 comments
    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <set>
    #include <algorithm>
    using namespace std;
    
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int Q;
        cin >> Q;
    
        set<int> s;
    
        for (int i = 0; i < Q; i++) {
            int queryType, queryValue;
            cin >> queryType >> queryValue;
    
            if (queryType == 1) {
                s.insert(queryValue);
            } else if (queryType == 2) {
                s.erase(queryValue);
            } else if (queryType == 3) {
                set<int>::iterator it = s.find(queryValue);
                if (it != s.end()) {
                    cout << "Yes" << endl;
                } else {
                    cout << "No" << endl;
                }
            }
        }
    
        return 0;
    }
    
  • + 1 comment
    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <set>
    #include <algorithm>
    using namespace std;
    
    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++){
            int query;
            int x;
            cin>>query;
            cin>>x;
            switch (query) {
            case 1:
                s.insert(x);
                break;
            case 2:
                s.erase(x);
                break;
            case 3:
                auto itr=s.find(x);
                  
                if(itr !=s.end()) {
                    cout<<"Yes"<<endl;
                } 
                else{
                     cout<<"No"<<endl;
                }
                break;
            }
        }
        return 0;
    }
    
  • + 1 comment
    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <set>
    #include <algorithm>
    using namespace std;
    
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        size_t Q, y, x;
        cin >> Q;
        set<size_t> numbers;
        
        for(; Q > 0; Q--)
        {
            cin >> y >> x;
            
            switch (y)
            {
                case 1:
                    numbers.insert(x);
                    break;
                    
                case 2:
                    numbers.erase(x);
                    break;
                    
                case 3:
                    {
                        auto it = numbers.find(x);
                        cout << (it == numbers.end() ? "No" : "Yes") << endl;
                    }
                    
                    break;
            }
        }
        return 0;
    }
    
  • + 0 comments

    include

    include

    include

    include

    include

    include

    using namespace std;

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int n,x,y; cin>>n; sets; for(int i=0;i>x>>y; if(x==1) s.insert(y); else if(x==2) s.erase(y); else{ set::iterator itr = s.find(y); if(itr!=s.end()) cout<<"Yes"<

    }
    return 0;
    

    }

  • + 0 comments

    here is my solution

    include

    include

    include

    include

    include

    include

    using namespace std;

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int q; set s; int x, y;

    cin >> q;
    for(int i =0; i < q;i++){
        cin >> y >> x;
        if(y== 1){
        s.insert(x);
        }
        if(y ==2)
        {
            s.erase(x);
        }
        if(y ==3)
        {
            if(s.find(x)!=s.end())
            {
                cout << "Yes" << endl;
            }
            else 
            {
                cout << "No" << endl;
            }
        }
    

    }

    return 0;
    

    }