Cod sursa(job #1580680)

Utilizator aetherAlexandra Vanca aether Data 26 ianuarie 2016 00:14:03
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.2 kb
#include<fstream>
#define r 665124
using namespace std;

struct nod
{
    int info;
    nod *adr;
};
nod *v[r];
ifstream f("hashuri.in");
ofstream g("hashuri.out");

void adaug (nod *&p,int x)
{
    nod *q=new nod;
    q->info=x;
    q->adr=p;
    p=q;
}

void sterge (nod *&p, int x)
{
    if(p==NULL)
        return;
    nod *aux=new nod;
    if(p->info==x)
    {
        aux=p;
        p=p->adr;
        delete aux;
        return;
    }
    for (nod* q=p;q->adr;q=q->adr)
    {
        if(q->adr->info==x)
        {
            aux=p->adr;
            p->adr=aux->adr;
            delete aux;
            return;
        }
    }
}

void raspuns (nod *p, int x)
{
    int contor=0;
    while (p!=NULL)
    {
        if(p->info==x)
            contor=1;
        p=p->adr;
    }
    if(contor==1)
        g<<1;
    else
        g<<0;
    g<<'\n';
}
int main ()
{
    long int n,a,b;
    f>>n;
    while (n!=0)
    {
        f>>a;
        f>>b;
        if(a==1)
            adaug(v[b%r],b);
        if(a==2)
            sterge(v[b%r],b);
        if(a==3)
            raspuns(v[b%r],b);
        n--;
    }
    f.close();
    g.close();
    return 0;
}