Pagini recente » Cod sursa (job #1077914) | Castori | Cod sursa (job #308935) | Cod sursa (job #681444) | Cod sursa (job #1200440)
#include <iostream>
#include <cstdio>
#include <fstream>
#define HASH_SIZE 666013
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
struct node {
node* next;
int info;
// node() {
// this.next = NULL;
// this.info = 0;
// }
};
bool lookup(node hash[], int el) {
node& list = hash[el%HASH_SIZE];
while(list.info) {
if(list.info == el)
return true;
list = *list.next;
}
return false;
}
void add(node hash[], int el) {
if (lookup(hash, el)) {
return;
}
node& list = hash[el%HASH_SIZE];
while (list.info) {
list = *list.next;
}
list.info = el;
list.next = new node;
}
void remove(node hash[], int el) {
if (!lookup(hash, el)) {
return;
}
node& list = hash[el%HASH_SIZE];
while(list.info) {
if (list.info == el) {
node* aux = list.next;
list.info = (*aux).info;
list.next = (*aux).next;
delete aux;
return;
}
list = *list.next;
}
}
node hash[666013];
int main (int argc, char const *argv[])
{
int n;
in>>n;
int op, el;
for(int i=0; i<n; ++i) {
in>>op>>el;
if (op == 1)
add(hash, el);
if (op == 2)
remove(hash, el);
if (op == 3)
out<<lookup(hash, el)<<"\n";
}
return 0;
}