Cod sursa(job #1161617)

Utilizator xtreme77Patrick Sava xtreme77 Data 31 martie 2014 12:42:12
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <cstdio>
#define MOD 666013

using namespace std;

int hash[MOD+3][9];

void insert(int x);
void sterge(int x);
int check(int x);

int main()
{
    int n,i,op,x;
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d",&op,&x);
        if(op==1)insert(x);
        if(op==2)sterge(x);
        if(op==3)
            if(check(x)==-1)
                printf("0\n");
            else
                printf("1\n");
    }
    return 0;
}
void insert(int x)
{
    int i;
    i=check(x);
    if(i==-1)
        hash[x%MOD][++hash[x%MOD][0]]=x;
}
void sterge(int x)
{
    int poz= x%MOD, i;
    i=check(x);
    if(i!=-1)
        hash[poz][i]=-1;
}
int check(int x)
{
    int poz=x%MOD,i;
    for(i=1; i<=hash[poz][0]; i++)
        if(hash[poz][i]==x)
            return i;
    return -1;
}