Pagini recente » Cod sursa (job #640917) | Cod sursa (job #485059) | Cod sursa (job #2487502) | Cod sursa (job #243983) | Cod sursa (job #440828)
Cod sursa(job #440828)
/*
* File: main.cpp
* Author: VirtualDemon
*
* Created on April 12, 2010, 3:32 PM
*/
#include <cstdlib>
#include <fstream>
#define Modulo 666013
/*
*
*/
using namespace std;
struct hash
{
int info;
hash* next;
} *H[Modulo];
inline void add( int x, int p )
{
hash *q;
for( q=H[p]; q && q->info != x; q=q->next );
if( q )
return;
q=new hash;
q->info=x;
q->next=H[p];
H[p]=q;
}
inline void erase( int x, int p )
{
if( !H[p] )
return;
if( x == H[p]->info )
{
hash* q=H[p];
H[p]=H[p]->next;
delete q;
return;
}
hash *q, *qq;
for( q=H[p]; q->next && q->next->info != x; q=q->next );
if( !q->next )
return;
qq=q->next;
q->next=qq->next;
delete qq;
}
inline bool is_here( int x, int p )
{
if( !H[p] )
return false;
hash* q;
for( q=H[p]; q && x != q->info; q=q->next );
return NULL != q;
}
int main( void )
{
int N, i, j;
ifstream in( "hashuri.in" );
ofstream out( "hashuri.out" );
in>>N;
for( ; N; --N )
{
in>>i>>j;
switch( i )
{
case 1 : add( j, j%Modulo ); break;
case 2 : erase( j, j%Modulo ); break;
case 3 : out<<is_here( j, j%Modulo )<<'\n';
}
}
return EXIT_SUCCESS;
}