Cod sursa(job #267361)

Utilizator peanutzAndrei Homorodean peanutz Data 27 februarie 2009 09:09:06
Problema Hashuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include <stdio.h>
#include <stdlib.h>

#define MOD 310107

typedef struct nod
{
	long v;
	nod *urm;
} *pnod;

pnod list[MOD];
long n;

void baga(int poz, int x)
{
	pnod aux = new nod;
	aux -> v = x;
	aux -> urm = list[poz];
	list[poz] = aux;
}

int find(int poz, int x)
{
	pnod it;
	for(it = list[poz]; it != NULL; it = it -> urm)
		if(it -> v == x)
			return 1;
	return 0;
}

void remove(int poz, int x)
{
	pnod it, last = list[poz];
	if(last ->v == x)
			{       it = last;
				list[poz] = list[poz] -> urm;
				delete it;
			}
	 else
	for(it = list[poz]; it != NULL; it = it -> urm)
	{
		if(it -> v == x)
		{

			last -> urm = it -> urm;
			delete it;
			it=NULL;
		}
		last = it;
	}
}












int main()
{
	long o, x;
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);

	scanf("%ld", &n);

	while(n--)
	{
		scanf("%ld %ld", &o, &x);
		if(o == 1)
		{
			if(!find(x%MOD, x))
				baga(x%MOD, x);
                }
		else if(o == 2)
			remove(x%MOD, x);
		else
			printf("%d\n", find(x%MOD, x));
	}
	return 0;
}