Pagini recente » Cod sursa (job #302557) | Cod sursa (job #1584927) | Cod sursa (job #2427056) | Cod sursa (job #2002451) | Cod sursa (job #1181543)
#include<fstream>
#include<stdlib.h>
#include<stdio.h>
#define dim 90010
#define P 90007
using namespace std;
typedef struct list{
int K;
struct list* next;
} List;
typedef List* Hash[dim];
Hash H;
inline void inithash(){
for(int i=0;i<dim;H[i++]=NULL);
}
inline int h(int val){
return val % P;
}
void Add(int val){
List* L=(List*)malloc(sizeof(List));
L->K=val;
L->next=H[h(val)];
H[h(val)]=L;
}
bool search(int val){
List* L;
for(L=H[h(val)];L && L->K!=val;L=L->next);
return L != NULL;
}
void del(int val){
List* L;
for(L=H[h(val)];L && L->K!=val;L=L->next);
if(L != NULL){
if(L->next==NULL) free(L);
else{
L->K=L->next->K;
L->next=L->next->next;
}
}
}
int main(){
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int x,tip,i,n;
f>>n;
inithash();
for(i=1;i<=n;i++){
f >> tip >> x;
if(tip==1){
Add(x);
}
if(tip==2){
del(x);
}
if(tip==3){
g << search(x) << "\n";
}
}
}