Cod sursa(job #1098725)

Utilizator cont_de_testeCont Teste cont_de_teste Data 5 februarie 2014 01:38:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

struct Hash {
	int elem;
	Hash *next;
};

const int key = 100005;
Hash *H[key];

void add(const int &V) {
	Hash *D = new Hash;
	D->elem = V;
	D->next = H[V % key];
	H[V % key] = D;
}

void del(const int &V) {
	for (Hash *X = H[V % key]; X != NULL; X = X->next)
		if (X->elem == V) {
			X->elem = 0;
			return ;
		}
}

int ask(const int &V) {
	for (Hash *X = H[V % key]; X != NULL; X = X->next)
		if (X->elem == V)
			return 1;
	return 0;
}

int main() {
	int N;
	for (fin >> N; N--; ) {
		int Q, V;
		fin >> Q >> V;
		if (Q == 1)
			add(V);
		else if (Q == 2)
			del(V);
		else
			fout << ask(V) << '\n';
	}
	fin.close();
	fout.close();
}