Cod sursa(job #1774582)

Utilizator Data 9 octombrie 2016 09:12:24 Hashuri 100 cpp done Arhiva educationala 1.35 kb
``````#include <stdio.h>
#include <stdlib.h>
#define MAXN 1000000
#define MOD 666013

int v[MAXN], lista[MOD], next[MAXN];

void adauga( int x, int p ) {
v[p] = x;
next[p] = lista[x%MOD];
lista[x%MOD] = p;
}
void sterge( int x ) {
int p;
p = lista[x%MOD];
if ( v[p] == x )
lista[x%MOD] = next[p];
else {
while ( v[next[p]] != x && next[p] != 0 )
p = next[p];
if ( v[next[p]] == x )
next[p] = next[next[p]];
}
}
bool cauta(int x) {
int p;
p = lista[x%MOD];
while ( p != 0 && v[p] != x )
p = next[p];
return v[p] == x;
}

int main() {
FILE *fin, *fout;
int n, i, caz, x;
fin = fopen( "hashuri.in", "r" );
fout = fopen( "hashuri.out", "w" );
fscanf( fin, "%d", &n );
for ( i = 1; i <= n; i++ ) {
fscanf( fin, "%d%d", &caz, &x );
switch(caz)  {
case 1:
if ( cauta( x ) == 0 )
break;
case 2:
if ( caz == 2 )
sterge( x );
break;
case 3:
if(cauta(x)==true)
fprintf( fout, "1\n" );
else
fprintf(fout, "0\n");
break;
}
}

fclose( fin );
fclose( fout );
return 0;
}
``````