Cod sursa(job #1112350)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 19 februarie 2014 18:34:41
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>
#include <algorithm>
#include <set>

using namespace std;

class Hash {
  public:
    Hash() {}

    void Insert(const int value) {
        table[GetKey(value)].insert(value);
    }

    bool Find(const int value) const {
        return (table[GetKey(value)].count(value) > 0);
    }

    void Erase(const int value) {
        table[GetKey(value)].erase(value);
    }

  private:
    static const int U = 666013;
    set<int> table[U];

    static int GetKey(const int value) {
        return value % U;
    }
};

int main() {
    ifstream cin("hashuri.in");
    ofstream cout("hashuri.out");
    Hash hash;
    int q;
    cin >> q;
    for (; q > 0; --q) {
        int type, value;
        cin >> type >> value;
        if (type == 1)
            hash.Insert(value);
        else if (type == 2)
            hash.Erase(value);
        else if (type == 3)
            cout << hash.Find(value) << "\n";
    }
    cin.close();
    cout.close();
    return 0;
}