Cod sursa(job #244536)

Utilizator alex3el_n2oAlex Vladescu alex3el_n2o Data 15 ianuarie 2009 13:03:09
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.34 kb
#include <stdio.h>

struct nod{
	long a;
	nod *adr;
	} *prim[666030];  //666030
long X=666013;

void f1(long t)
	{
	int p=1;
	long rest=t%X;
	nod *aux,*sf;
	if (prim[rest]==NULL)
		{
		aux=new nod;
		aux->a=t;
		aux->adr=NULL;
		prim[rest]=aux;
		}
	else
		{
		//verif - go
		aux=new nod;
		aux=prim[rest];
		while (aux!=NULL)
			{
			if (aux->a==t) p=0;
			if (aux->adr==NULL) sf=aux->adr;
			aux=aux->adr;
			}
		if (p) {
			aux=new nod;
			aux->a=t;
			aux->adr=NULL;
			sf->adr=aux;
			}
		}
	}

void f2(long t)
	{
	long rest=t%X;
	nod *aux,*aux2;
	if (prim[rest]!=NULL)
		{
		aux=new nod;
		aux=prim[rest];
		if (aux->adr->a==0)
			{
			aux=NULL;
			prim[rest]=aux;
			}
		else
		while (aux!=NULL)
			{
			if (aux->a==t)
				aux2->adr=aux->adr;
			aux2=aux;
			aux=aux->adr;
			}
		}
	}

int f3(long t)
	{
	long rest=t%X;
	nod *aux;
	int p=0;
	if (prim[rest]==NULL)
		return 0;
	else
		{
		aux=new nod;
		aux=prim[rest];
		while (aux!=NULL)
			{
			if (aux->a==t) p=1;
			aux=aux->adr;
			}
		return p;
		}
	}

int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
long n,i,x;
int tip;
scanf("%ld",&n);
for (i=1;i<=n;i++)
	{
	scanf("%d %ld",&tip,&x);
	if (tip==1) f1(x);
	if (tip==2) f2(x);
	if (tip==3) printf("%d\n",f3(x));
	}
return 0;
}