Cod sursa(job #2106990)

Utilizator biaiftimeIftime Bianca biaiftime Data 16 ianuarie 2018 17:13:33
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <fstream>
#define Prim 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
struct nod
{
    int info;
    nod *urm;
};
nod *h[Prim];
void Insert(int x,nod *&prim)
{
    nod *q=new nod;
    q->info=x;
    q->urm=prim;
    prim=q;
}
void Delete(int x,nod *&prim)
{
    nod *q;
    nod *prec;
    int ok=0;
    for(q=prim;q!=NULL;prec=q,q=q->urm)
    if(q->info==x){ok=1; break; }
    if(ok==1)
    {
        if(q==prim)
            prim=NULL;
        else
        {
            prec->urm=q->urm;
            delete q;
        }
    }
}
int Search(int x,nod *prim)
{
    nod *q;
    for(q=prim;q!=NULL;q=q->urm)
    if(q->info==x)return 1;
    return 0;
}
int main()
{
    int i,n,op,x,poz;
    fin>>n;
    for(i=1;i<=n;++i)
    {
        fin>>op>>x;
        poz=x%Prim;
        if(op==1)Insert(x,h[poz]);
        if(op==2)Delete(x,h[poz]);
        if(op==3)fout<<Search(x,h[poz])<<"\n";
    }
    return 0;
}