Cod sursa(job #844036)

Utilizator Brz_VladBrezae Vlad Brz_Vlad Data 28 decembrie 2012 19:03:30
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.37 kb
#include <stdio.h>

///////////////////// LIST /////////////////////
struct Node
{
	int value;
	struct Node *next;
};

struct List
{
	Node* start;

	List(){
		start = NULL;
	}

	void addList(int value){
		if( findList(value) )
			return;
		
		Node *niu = new Node;
		niu->next = this->start;
		niu->value = value;
		this->start = niu;
	}

	bool findList(int value){
		Node *q = this->start;
		while( q != NULL){
			if( q->value == value )
				return true;
			q = q->next;
		}
		
		return false;
	}
	
	void delList(int value){
		if( this->start == NULL )
			return;
		
		if( this->start->value == value ){
			this->start = this->start->next;
			return;
		}
		
		Node *q = this->start;
		while( q->next != NULL ){
			if( q->next->value == value ){
				Node* toDel = q->next;
				q->next = q->next->next;
				delete toDel;
				return;			
			}
			q = q->next;
		}
	}
};
/////////////////////////////////////////////////

#define MAXN 100000
int N;

List hash[MAXN];

int main(int argc, char* argv[])
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	
	scanf("%d",&N);
	
	int i,op,val;
	for(i=0;i<N;i++){
		scanf("%d %d",&op,&val);
		switch(op){
			case 1:
				hash[val%MAXN].addList(val);
				break;
			case 2:
				hash[val%MAXN].delList(val);
				break;
			case 3:
				if( hash[val%MAXN].findList(val) )
					printf("1\n");
				else
					printf("0\n");
				break;
		}
	}	
	
	return 0;
}