Cod sursa(job #1171337)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 15 aprilie 2014 16:33:59
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>
#include <vector>
#define modulo 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> hash[modulo];
int n, i, op, x;

vector<int>::iterator hash_find(int x) {
    int list=x%modulo;
    for (vector<int>::iterator it = hash[list].begin(); it!=hash[list].end(); it++)
        if (*it == x)
            return it;
    return hash[list].end();
}

void hash_insert(int x) {
    int list=x%modulo;
    if (hash_find(x) == hash[list].end())
        hash[list].push_back(x);
}

void hash_delete(int x) {
    int list=x%modulo;
    vector<int>::iterator it = hash_find(x);
    if (it!=hash[list].end())
        hash[list].erase(it);
}

int main()
{
    f>>n;
    for (i=1; i<=n; i++) {
        f>>op>>x;
        if (op==1)
            hash_insert(x);
        else if (op==2)
            hash_delete(x);
        else
            if (hash_find(x) != hash[x%modulo].end()) g<<1<<"\n";
            else g<<0<<"\n";
    }
    return 0;
}