Pagini recente » Cod sursa (job #2167928) | Cod sursa (job #2524476) | Cod sursa (job #1955123) | Cod sursa (job #497824) | Cod sursa (job #2122441)
#include <iostream>
#include <fstream>
using namespace std;
const int MAXN = 1000001;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
struct node{
int info;
node *next;
};
struct list{
node *first, *last;
list(){
first = last = NULL;
}
void insert(int x){
node *c = new node{x, NULL};
if(!first){
first = last = c;
return;
}
last->next = c;
last = c;
}
void remove(int x){
if(first->info == x){
node *c = first;
first = first->next;
delete c;
return;
}
node *prev = first;
for(node *i = first->next; i;prev = i, i = i->next){
if(i->info == x){
node *c = i;
prev->next = i->next;
delete c;
return;
}
}
}
bool find(int x){
for(node *i = first; i; i = i->next)
if(i->info == x)
return true;
return false;
}
}h[MAXN];
bool hashFind(int nod){
int pos = nod % MAXN;
return h[pos].find(nod);
}
void hashInsert(int nod){
int pos = nod % MAXN;
h[pos].insert(nod);
}
void hashRemove(int nod){
int pos = nod % MAXN;
h[pos].remove(nod);
}
int q;
int main(){
in >> q;
while(q--){
int op, param;
in >> op >> param;
if(op == 1){
hashInsert(param);
} else if(op == 2){
if(hashFind(param))
hashRemove(param);
} else {
out<< hashFind(param)<<'\n';
}
}
return 0;
}