Cod sursa(job #1520877)

Utilizator 3DwArDPauliuc Edward 3DwArD Data 9 noiembrie 2015 17:36:26
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <bits/stdc++.h>

using namespace std;
const int MOD= 666013;
vector<int> HASH[MOD];
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int hash_querry(int x)
{
    int line=x%MOD;
    for(int i=0;i<HASH[line].size();i++)
        if(HASH[line][i]==x)
        return 1;
    return 0;
}
void hash_insert(int x)
{
 int line=x%MOD;
 if(hash_querry(x)==0)
        HASH[line].push_back(x);
}
void hash_delete(int x)
{
    int line=x%MOD;
    for(int i=0;i<HASH[line].size();i++)
    {
        if(HASH[line][i]==x)
        {
            HASH[line].erase(HASH[line].begin()+i);

        }

    }
}
int main()
{
    int n,type,x;
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>type>>x;
        switch(type)
        {
            case 1: hash_insert(x);
            break;
            case 2: hash_delete(x);
            break;
            case 3: g<<hash_querry(x)<<"\n";
            break;
        }
    }
    return 0;
}