Pagini recente » Cod sursa (job #1235745) | Info Oltenia 2018 Proba pe Echipe Clasele 11 - 12 | Cod sursa (job #2912462) | Cod sursa (job #2912454) | Cod sursa (job #2152674)
#include <stdio.h>
#include <stdlib.h>
#define mod 399993
int n,x;
typedef struct node{
int value;
int freq;
struct node *next;
}LLIST;
LLIST *hash[mod];
void insert(LLIST **head, int value){
if((*head) == NULL){
LLIST *aux = (LLIST *)calloc(1,sizeof(LLIST));
aux->value = value;
aux->freq = 1;
aux->next = NULL;
(*head) = aux;
}else{
LLIST *p = (*head);
for(; p && p->value != value; p = p->next);
if(p == NULL){
LLIST *aux = (LLIST *)calloc(1,sizeof(LLIST));
aux->value = value;
aux->freq = 1;
aux->next = (*head);
(*head) = aux;
}
}
}
void del(LLIST **head, int value){
if((*head) == NULL){
}else{
if((*head)->value == value){
LLIST *aux = (*head);
(*head) = (*head)->next;
free(aux);
return;
}
LLIST *p = (*head), *q;
for(; p && p->value != value; q = p, p = p->next);
if(p == NULL){
}else{
LLIST *aux = p;
q->next = p->next;
free(aux);
}
}
}
int get(LLIST *head, int value){
if(head == NULL){
return 0;
}else{
LLIST *p = head;
for(; p && p->value != value; p = p->next);
if(p == NULL){
return 0;
}else{
return 1;
}
}
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
for(int i = 1; i <= n; ++i){
int q,x;
scanf("%d%d",&q,&x);
int local_hash = x % mod;
if(q == 1){
insert(&hash[local_hash],x);
}else
if(q == 2){
del(&hash[local_hash],x);
}else
if(q == 3){
printf("%d\n",get(hash[local_hash],x));
}
}
return 0;
}