Sets-STL

Sort by

recency

|

326 Discussions

|

  • + 0 comments

    include

    include

    include

    include

    using namespace std;

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int queries; cin >> queries; cin.ignore();

    set<int> s;
    
    for (int i = 0; i < queries; i++) {
        int type, num;
    
        cin >> type >> num;
    
        auto it = s.find(num);
    
        switch (type) {
            case 1:
                s.insert(num);
                break;
            case 2:
                s.erase(num);
                break;
            case 3:
                if (it != s.end() && *it == num) {
                    cout << "Yes" << endl;
                } else {
                    cout << "No" << endl;
                }
                break;
            default:
                break;
        }
    }
    return 0;
    

    }

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

    }