Cod sursa(job #1074693)

Utilizator alexsuciuAlex Suciu alexsuciu Data 7 ianuarie 2014 21:16:51
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
#include <iostream>
#include <fstream>
using namespace std;
int n,x,tip,i;
long  m =666013;

struct nod
{
    int val;
    nod *next;
};
nod *h[666013];

int main()
{nod *p,*c,*e;
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>tip>>x;
        if(tip==1)
        {
            for(p=h[x%m];p && p->val!=x;p=p->next);
            if(!p)
            {
                c=new nod;
                c->val=x;
                c->next=h[x%m];
                h[x%m]=c;
            }
        }
        else if (tip==2)
        {
            p=h[x%m];
            e=h[x%m];
            if(p)
            {
       if(p->val==x)
    {
        c=h[x%m];
        h[x%m]=h[x%m]->next;
        delete c;
    }
    else
    {while (e->next != NULL && e->next->val != x)
    e=e->next;
    if (e->next!= NULL)
    {
    c=e->next;
    e->next=e->next->next;
    delete c;
    }}}
        }
        else if(tip==3)
        {
            for(p=h[x%m];p && p->val!=x;p=p->next);
            if(p)
                g<<1<<'\n';
                else g<<0<<'\n';

        }
    }
}