Cod sursa(job #1017993)

Utilizator Catalina_BrinzaBrinza Catalina Catalina_Brinza Data 28 octombrie 2013 19:10:16
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.45 kb
//
//  main.cpp
//  hasuri
//
//  Created by Catalina Brinza on 10/26/13.
//  Copyright (c) 2013 Catalina Brinza. All rights reserved.
//

#include <iostream>
#include <fstream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");

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

void h2(int x)
{
    nod *q=new nod;
    nod *m=new nod;
    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)
{
    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;
    
}

void dele(nod *p)
{
    if (p->next!=NULL)
        dele(p->next);
        delete p;
}


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

        
}