Pagini recente » Cod sursa (job #3187633) | Cod sursa (job #3174943) | Cod sursa (job #513041) | Cod sursa (job #1672048) | Cod sursa (job #1147546)
#include <cstdio>
#include <vector>
#define MOD 1000007
using namespace std;
struct Hash {
vector <int> V[MOD];
bool find( int x ) {
int key = x % MOD;
int poz = 0;
while( poz < V[key].size() && V[key][poz] != x )
++poz;
if( poz < V[key].size() )
return true;
return false;
}
void add( int x ) {
V[x%MOD].push_back( x );
}
void erase( int x ) {
int key = x % MOD, poz = 0;
while( V[key][poz] != x )
++poz;
V[key][poz] = V[key][V[key].size()-1];
V[key].pop_back();
}
};
Hash H;
int main () {
FILE *f, *g;
f = fopen( "hashuri.in", "r" );
g = fopen( "hashuri.out", "w" );
int n, op, x;
fscanf( f, "%d", &n );
for( int i = 0 ; i < n ; ++i ) {
fscanf( f, "%d%d", &op, &x );
switch( op ) {
case 1:
H.add( x );
break;
case 2:
if( H.find( x ) )
H.erase( x );
break;
case 3:
fprintf( g, "%d\n", H.find( x ) );
break;
}
}
fclose( f );
fclose( g );
return 0;
}