Cod sursa(job #1171340)

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

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

void hasht_insert(int x) {
    int list=x%modulo;
    if (hasht_find(x) == hasht[list].end())
        hasht[list].push_back(x);
}

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

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