Cod sursa(job #440828)

Utilizator alexandru92alexandru alexandru92 Data 12 aprilie 2010 16:10:14
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
/* 
 * 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;
}