Pagini recente » Cod sursa (job #903421) | Cod sursa (job #592354) | Cod sursa (job #561733) | Cod sursa (job #3128213) | Cod sursa (job #1972342)
#include <iostream>
#include <fstream>
using namespace std;
const int MAXN = 1000001;
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 hash_find(int nod){
int pos = nod % MAXN;
return h[pos].find(nod);
}
void hash_insert(int nod){
int pos = nod % MAXN;
h[pos].insert(nod);
}
void hash_remove(int nod){
int pos = nod % MAXN;
h[pos].remove(nod);
}
int q;
int main(){
ifstream in("hashuri.in");
ofstream out("hashuri.out");
in>>q;
while(q--){
int op, param;
in>>op>>param;
if(op == 1){
hash_insert(param);
} else if(op == 2){
if(hash_find(param))
hash_remove(param);
} else {
out<< hash_find(param)<<'\n';
}
}
return 0;
}