Cod sursa(job #2268203)

Utilizator cezarzbughinCezar Zbughin cezarzbughin Data 24 octombrie 2018 16:23:25
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int N = 100003; /// un numar prim utilizat in tabela de dispersie ( tabela hash )
struct nod
{
    int info;
    nod *nxt;
};
nod *H[N],*p,*q;
int n,o,x,h;
int main()
{
    f>>n;
    for(;n;n--)
    {
        f>>o>>x;
        h=x%N;
        for(p=H[h];p;p=p->nxt)
            if(p->info==x)
                break;
        if(o==1&&p==NULL)
        {
            q=new nod;
            q->info=x;
            q->nxt=H[h];
            H[h]=q;
        }
        else if(o==2&&p!=NULL)
        {
            p->info=H[h]->info;
            q=H[h];
            H[h]=q->nxt;
            delete q;
        }
        else if(o==3)
        {
            if(p==NULL)
                g<<"0\n";
            else
                g<<"1\n";
        }
    }
    return 0;
}