Pagini recente » Cod sursa (job #2706535) | Cod sursa (job #634799) | Cod sursa (job #1947847) | Cod sursa (job #1423581) | Cod sursa (job #481737)
Cod sursa(job #481737)
#include<stdio.h>
#include<stdlib.h>
#define r 666013
typedef struct nod{
int data;
struct nod *next;
};
nod *v[r];
void adauga(int x, nod **l){
nod *t;
t = (nod*)malloc(sizeof(nod));
t->data = x;
t->next = *l;
*l = t;
}
int cauta(int x,nod *l){
while(l != NULL){
if(x == l->data)
return 1;
l = l->next;
}
return 0;
}
void sterge(int x,nod **l){
nod *p = *l,*q;
if(p==NULL)
return;
if(p->data == x)
{
*l = p->next;
free(p);
return;
}
while(p->next != NULL){
if(x == p->next->data){
q = p->next;
p->next = q->next;
free(q);
return;
}
p = p->next;
}
}
int main(){
FILE *f,*g;
int n,i,k,x,t;
f = fopen("hashuri.in","r");
g = fopen("hashuri.out","w");
fscanf(f,"%d",&n);
for(i = 0;i < n;i++){
fscanf(f,"%d%d",&k,&x);
if(k == 1)
adauga(x,&v[x % r]);
else if(k == 2)
sterge(x,&v[x % r]);
else{
t = cauta(x,v[x % r]);
fprintf(g,"%d\n",t);
}
}
fclose(f);
fclose(g);
return 0;
}