Cod sursa(job #2183811)

Utilizator laur4444Olteanu Laurentiu laur4444 Data 23 martie 2018 14:42:19
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 1.44 kb
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#define HMAX 66013
using namespace std;
int mHash(int x) {
    return x % HMAX;
}
int main()
{
    ifstream in("hashuri.in");
    ofstream out("hashuri.out");
    vector<int> hashTable[HMAX];

    int n, x, op, xHash;
    bool ok;

    in >> n;
    for(int i = 0; i < n; i++) {
        in >> op >> x;
        xHash = mHash(x);
        ok = true;

        switch (op) {
        case 1:
            for(vector<int>::iterator j = hashTable[xHash].begin(); j != hashTable[xHash].end(); j++)
                if(*j == x) {
                    ok = false;
                    break;
                }
            if(ok)
                hashTable[xHash].push_back(x);
            break;
        case 2:
            for(vector<int>::iterator j = hashTable[xHash].begin(); j != hashTable[xHash].end(); j++)
                if(*j == x) {
                    hashTable[xHash].erase(j);
                    break;
                }
            break;
        case 3:
            for(vector<int>::iterator j = hashTable[xHash].begin(); j != hashTable[xHash].end(); j++)
                if(*j == x) {
                    ok = false;
                    out << 1 << endl;
                    break;
                }
            if(ok)
                out << 0 << endl;
            break;
        }
    }
    in.close();
    out.close();
    return 0;
}