Cod sursa(job #2938604)

Utilizator EasyTnsEasyTns EasyTns Data 12 noiembrie 2022 13:06:53
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.62 kb
#include<fstream>
#include<cmath>
//#include<iostream>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
double y=(sqrt(5)-1)/2;
int m;
struct nod{
    int info=0;
    nod *urm=NULL;
}*h[10000002];
void inserare(nod *&prim,int val)
{
    nod*t=new nod;
    t->info=val;
    t->urm=prim;
    prim=t;
}
 int get_index(int x)
{

    return m*(x*y-floor(x*y));

}
void cautare(nod *prim,int val)
{
    int gasit=0;
    if(prim==NULL)
        cout<<"0\n";
    else
    {
        nod *p=prim;
        while(p!=NULL)
        {
            if(p->info==val)
            {gasit=1;break;}
            p=p->urm;
        }
        if(gasit==1)
            cout<<"1\n";
        else
            cout<<"0\n";

    }
}
void parcurgere(nod *prim,int val)
{
    int gasit=0;
    if(prim==NULL)
        cout<<"0\n";
    else
    {
        nod *p=prim;
        while(p!=NULL)
        {
            cout<<p->info<<' ';
            p=p->urm;
        }


    }
}
void stergere(nod *&prim,int val)
{
    if(prim==NULL)
        return ;
    nod *t;
    if(prim->info==val)
    {
        t=prim;
        prim=prim->urm;
        delete t;
        return ;
    }
    t=prim;
        while(t->info!=val&&t->urm!=NULL)
        {
            t=t->urm;
        }
        if(t->info!=val)
            return;
        nod *p=t;
        p=p->urm;
        delete t;



}
int main()
{
    int n;
    m=1000000;
    cin>>n;
    int x,j;
for(;n;n--)
{
    cin>>x>>j;
    if(x==1)
        inserare(h[get_index(j)],j);
    else
        if(x==2)
        {
            stergere(h[get_index(j)],j);
        }
        else if(x==3)
            cautare(h[get_index(j)],j);
}

}