Pagini recente » Cod sursa (job #147182) | Cod sursa (job #1258926) | Cod sursa (job #2903148) | Cod sursa (job #2187362) | Cod sursa (job #1017877)
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
vector<int> hashu[886381];
int hashFunc (int nr)
{
return nr % 886381;
}
int cauta(int n);
void adaugare (int val)
{
// <----- ce tampenie ------>
if (cauta(val) == 1)
return;
hashu[hashFunc(val)].push_back(val);
}
void stergere (int val)
{
int hashed = hashFunc(val);
for (vector<int>::iterator i = hashu[hashed].begin(); i != hashu[hashed].end(); ++i)
if (*i == val)
{
hashu[hashed].erase(i);
return;
}
}
int cauta(int val)
{
int hashed = hashFunc(val);
for (vector<int>::iterator i = hashu[hashed].begin(); i != hashu[hashed].end(); ++i)
if (*i == val)
return 1;
return 0;
}
int main()
{
FILE *fin, *fout;
fin = fopen( "hashuri.in", "r" );
int q;
fscanf( fin, "%d", &q );
fout = fopen( "hashuri.out", "w" );
while ( q ) {
int type, val;
fscanf( fin, "%d%d", &type, &val );
if (type == 1)
adaugare(val);
else if (type == 2)
stergere(val);
else
fprintf( fout, "%d\n", cauta(val) ? 1 : 0 );
--q;
}
fclose( fin );
fclose( fout );
return 0;
}