Cod sursa(job #267523)

Utilizator peanutzAndrei Homorodean peanutz Data 27 februarie 2009 16:38:59
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <stdio.h>
#include <stdlib.h>

#define MOD 610107

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

pnod list[MOD];
long n;

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

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

void remove(long poz, long x)
{
	pnod it;

		//last = list[poz];
		for(it = list[poz]; it != NULL; it = it -> urm)
		{
			if(it -> v == x)
			{
				it -> v = 0;

				return ;
			}
		}
}


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;
}