Pagini recente » Cod sursa (job #211316) | Cod sursa (job #943150) | Cod sursa (job #2273079) | Cod sursa (job #1623019) | Cod sursa (job #456429)
Cod sursa(job #456429)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on May 15, 2010, 2:07 PM
*/
#include <cstdlib>
#include <fstream>
#define Modulo 666013
/*
*
*/
using namespace std;
struct hash
{
int x;
hash* next;
hash( void ) : x(0), next(NULL) { }
} *H[Modulo];
typedef hash* hh;
inline void Add( hh& r, int x )
{
if( !r || x == r->x )
{
r=new hash;
r->x=x;
return;
}
hh p;
for( p=r; p; p=p->next )
if( x == p->x )
return;
p=new hash;
p->x=x;
p->next=r;
r=p;
}
inline bool Search( hh r, int x )
{
for( ;r && x != r->x; r=r->next );
return NULL != r;
}
inline void Del( hh& r, int x )
{
if( !r )
return;
hh p;
if( x == r->x )
{
p=r;
r=r->next;
delete p;
return;
}
for( p=r; p->next && x != p->next->x; p=p->next );
if( NULL == p->next )
return;
hh q=p->next;
p->next=q->next;
delete q;
}
int main( void )
{
int N, i, j;
ifstream in( "hashuri.in" );
ofstream out( "hashuri.out" );
for( in>>N; N; --N )
{
in>>i>>j;
switch(i)
{
case 1 : Add( H[j%Modulo], j ); break;
case 2 : Del( H[j%Modulo], j ); break;
case 3 : out<<Search( H[j%Modulo], j )<<'\n';
}
}
return EXIT_SUCCESS;
}