Pagini recente » Cod sursa (job #1044830) | Cod sursa (job #2233323) | Cod sursa (job #896838) | Cod sursa (job #1829921) | Cod sursa (job #591849)
Cod sursa(job #591849)
#include <iostream>
#include <cstdio>
#include <vector>
#define U 1000003
#define Adaugare 1
#define Stergere 2
#define Cautare 3
using namespace std;
vector <long> H[U];
long N;
vector <long> :: iterator Seek (long X)
{
vector <long> :: iterator it;
long Key;
Key=X%U;
for (it=H[Key].begin (); it!=H[Key].end (); it++)
{
if (*it==X)
{
return it;
}
}
return it;
}
void Insert (long X)
{
vector <long> :: iterator it;
long Key;
Key=X%U;
it=Seek(X);
if (it==H[Key].end ())
{
H[Key].push_back (X);
}
}
void Delete (long X)
{
vector <long> :: iterator it;
long Key;
Key=X%U;
it=Seek (X);
if (it!=H[Key].end() )
{
H[Key].erase (it);
}
}
int main()
{
FILE *fin = fopen ("hashuri.in", "r");
FILE *fout = fopen ("hashuri.out", "w");
long Tip=0, X=0, i;
fscanf (fin, "%ld", &N);
for (i=0; i<N; i++)
{
fscanf (fin, "%ld %ld", &Tip, &X);
if (Tip==Adaugare)
{
Insert (X);
}
if (Tip==Stergere)
{
Delete (X);
}
if (Tip==Cautare)
{
if (Seek (X)==H[X%U].end ())
{
fprintf (fout, "0\n");
}
else
{
fprintf (fout, "1\n");
}
}
}
fclose (fin);
fclose (fout);
return 0;
}