Cod sursa(job #246912)

Utilizator znakeu2znakeu znakeu2 Data 21 ianuarie 2009 20:32:45
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.29 kb
#include <stdio.h>
#define MAXN 666013

struct S8354 //random name goes here!!!
{
	int v;
	S8354 *n;
};

int n;
S8354 *V[MAXN+1];

void add(int k)
{
	int t=0;
	S8354 *p1=V[k % MAXN];
	
	while (p1!=NULL && t==0)
	{
		if (p1->v==k)
			t=1;
		p1=p1->n;
	}
	
	if (t==0)
	{
		p1=new S8354;
		p1->v=k; p1->n=V[k % MAXN]; V[k % MAXN]=p1;		
	}
//  else Drink(beer); :) (its not adivce, i order you to go get a beer n drink it!!!)
//  see, my sources have subliminal messages! (and hopefully they are typo-free)
}

void kill(int k)
{
	int t=0;
	S8354 *p1=V[k % MAXN],*p2=NULL;
	
	if (V[k % MAXN]!=NULL)
		if (V[k % MAXN]->v == k)
		{
			V[k % MAXN]=V[k % MAXN]->n;
			return;
		}
	
	while (p1!=NULL && t==0)
	{
		if (p1->v==k)
		{
			p2->n=p1->n;
			return;
		}
		p2=p1; p1=p1->n;		
	}	
}

int serci(int k)
{
	int t=0;
	S8354 *p1=V[k % MAXN];
	
	while (p1!=NULL && t==0)
	{
		if (p1->v==k)
			t=1;
		p1=p1->n;
	}
	
	return t;	
}

int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	
	int t,x;
	
	scanf("%d",&n);
	
	for (int i=0; i<n; ++i)
	{
		scanf("%d%d",&t,&x);
		if (t==1)
			add(x);
		if (t==2)
			kill(x);
		if (t==3)
			printf("%d\n",serci(x));
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}