Pagini recente » Cod sursa (job #865775) | Cod sursa (job #1895152) | Cod sursa (job #2594271) | Cod sursa (job #1816173) | Cod sursa (job #1463198)
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#define MOD 25000
#define list (key % MOD)
#define foreach(G) if(G) for ( hash_line* it = (G) ; it; it = it->next)
using namespace std;
struct hash_line{
int key;
hash_line* next;
} *Hash[MOD];
int key;
inline bool find_val(){
foreach(Hash[list])
if (it->key == key) return 1;
return 0;
}
inline void insert_val(){
foreach(Hash[list]) if (it->key == key) return;
hash_line *New = new hash_line;
New->key = key, New->next = Hash[list];
Hash[list] = New;
}
inline void erase_val(){
foreach(Hash[list]){
if (it->key == key){
hash_line *next = Hash[list]->next;
delete Hash[list];
Hash[list] = next;
return;
}
if (!it->next) return;
if (it->next->key == key){
hash_line *next = it->next->next;
delete it->next;
it->next = it->next->next;
return;
}
}
}
int main(){
int N, type;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
for (scanf("%d", &N); N; --N){
scanf("%d %d", &type, &key);
switch (type){
case 1:
insert_val();
break;
case 2:
erase_val();
break;
case 3:
printf("%d\n", find_val());
break;
}
}
return 0;
}