Pagini recente » Cod sursa (job #1666137) | Cod sursa (job #1761437) | Cod sursa (job #1282721) | Cod sursa (job #1329876) | Cod sursa (job #844038)
Cod sursa(job #844038)
#include <stdio.h>
///////////////////// LIST /////////////////////
struct Node
{
int value;
struct Node *next;
};
struct List
{
Node* start;
List(){
start = NULL;
}
void addList(int value){
if( findList(value) )
return;
Node *niu = new Node;
niu->next = this->start;
niu->value = value;
this->start = niu;
}
bool findList(int value){
Node *q = this->start;
while( q != NULL){
if( q->value == value )
return true;
q = q->next;
}
return false;
}
void delList(int value){
if( this->start == NULL )
return;
if( this->start->value == value ){
this->start = this->start->next;
return;
}
Node *q = this->start;
while( q->next != NULL ){
if( q->next->value == value ){
Node* toDel = q->next;
q->next = q->next->next;
delete toDel;
return;
}
q = q->next;
}
}
};
/////////////////////////////////////////////////
#define MAXN 1000000
int N;
List hash[MAXN];
int main(int argc, char* argv[])
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&N);
int i,op,val;
for(i=0;i<N;i++){
scanf("%d %d",&op,&val);
switch(op){
case 1:
hash[val%MAXN].addList(val);
break;
case 2:
hash[val%MAXN].delList(val);
break;
case 3:
if( hash[val%MAXN].findList(val) )
printf("1\n");
else
printf("0\n");
break;
}
}
return 0;
}