Cod sursa(job #1018072)

Utilizator Catalina_BrinzaBrinza Catalina Catalina_Brinza Data 28 octombrie 2013 20:45:59
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.62 kb


#include <iostream>
#include <fstream>
using namespace std;
ifstream f("/Users/catalinabrinza/Documents/untitled folder/hasuri/hasuri.in");
ofstream g("/Users/catalinabrinza/Documents/untitled folder/hasuri/hasuri.out");

struct nod
{
    int v;
    nod *next;
};
nod *a[41357]; int p=41357;
void h1(int x)
{nod *m=new nod;
    m->v=x;
    m->next=NULL;
    if (a[x%p]==NULL)
    {
        a[x%p]=new nod;
        a[x%p]=m;
    }
    else
    {
        nod *q=new nod;
        q=a[x%p];
        while (q->next!=NULL)
            if (q->v==x) return;
                else q=q->next;
        q->next=m;
        
    }
    return;
}

void h2(int x)
{
    if (a[x%p]!=NULL)
    {
    nod *q=new nod;
    nod *m=new nod;
        if (a[x%p]->v==x){ a[x%p]=a[x%p]->next;return;}
       else {m=a[x%p];
    q=m->next;
    while (m->next!=NULL)
        if (q->v==x) {
            m=q->next;
            delete q;
            return;
        }
           else {m=q; q=q->next;}}}
    return;
}

void h3(int x)
{if (a[x%p]!=NULL) {
    
    nod *m=new nod;
        m=a[x%p];
    while (m->next!=NULL)
        if (m->v==x){ g<<1<<"\n";return;}
        else m=m->next;
    g<<0<<"\n";return;
    }
else g<<0<<"\n";
    return;
}

void afisare (nod* n)
{
    while (n != NULL)
    {
        g << n->v<< " ";
        n = n->next;
    }
    
    g << "\n";
}

int main()
{int i,n,x,y;
    f>>n;
    for (i=0;i<p;i++) a[i]=NULL;
    for (i=0;i<n;i++)
    {
        f>>y>>x;
        if (y==1) h1(x);
        else if (y==2) h2(x);
        else h3(x);
    }
    for (int i = 0; i <= 20; i++)
        afisare(a[i]);
    f.close();
    g.close();
    return 0;

        
}