Pagini recente » Cod sursa (job #1335481) | Cod sursa (job #490791) | Cod sursa (job #2184231) | Cod sursa (job #860882) | Cod sursa (job #440819)
Cod sursa(job #440819)
/*
* 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 int h( int x )
{
return x%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;
for( q=H[p]; q->next && q->next->info != x; q=q->next );
if( !q->next )
return;
q->next=q->next->next;
delete q;
}
inline bool is_here( int x, int p )
{
if( !H[p] )
return false;
hash* q;
for( q=H[p]; q && q->info != x; 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, h(j) ); break;
case 2 : erase( j, h(j) ); break;
case 3 : out<<is_here( j, h(j) )<<'\n';
}
}
return EXIT_SUCCESS;
}