Cod sursa(job #711731)

Utilizator danalex97Dan H Alexandru danalex97 Data 12 martie 2012 18:59:03
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <fstream>
using namespace std;

#define Pmax 130451
#define RestMax 23
#define TipOp int

int H[Pmax][RestMax],N,x;
TipOp tip;

void Add(int X)
{
    int R=X%Pmax,t=0;
    for(; H[R][t]; t++);
    H[R][t]=X;
}

void Del(int X)
{
	int R=X%Pmax,t=0;
	for(; H[R][t]!=X && H[R][t]; t++);
	H[R][t]=0;
}

bool Caut (int X)
{	
	int R=X%Pmax,t=0;
	for(; H[R][t]!=X && H[R][t]; t++);
	
	if (H[R][t]==X)
		return 1;
	return 0;
}

inline void Tipar(int x)
{ if ( Caut(x) ) printf("1\n");
			else printf("0\n"); }

int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	
	scanf("%d",&N);
	
	for (int i=1;i<=N;++i)
	{
		scanf("%d%d",&tip,&x);
	
		if (tip==1) Add(x);
		if (tip==2) Del(x);
		if (tip==3) Tipar(x);
	
	}
	
	return 0;
}