Sets-STL

  • + 24 comments

    You don't need to declare an iterator object just to check if the value exists. And switch looks more suitable here than lot of if-then...

    int main() {
    int iCount;
    set<int> ss;
    cin >> iCount;
    for (int i=0; i<iCount; ++i){
        int type, query;
        cin >> type >> query;
        switch (type){
            case 1:
                ss.insert(query);
                break;
            case 2:
                ss.erase(query);
                break;
            case 3:
                cout << (ss.find(query) == ss.end() ? "No" : "Yes") << endl;
                break;
        }
    }  
    return 0;
    }