Pagini recente » Cod sursa (job #1493994) | Cod sursa (job #578462) | Cod sursa (job #721105) | Cod sursa (job #1232716) | Cod sursa (job #2529034)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int PRIM = 666013;
int fhash(int x)
{
return x % PRIM;
}
vector <int>h[PRIM+5];
vector <int> ::iterator it;
///am creat astfel tabela hash pentru a mainupa mai usor datele in cazul coleziunilor
bool find_x(int cod, int x)
{
if(h[cod].size()==0)
return false;
it = find(h[cod].begin(), h[cod].end(), x);
if(it!= h[cod].end())
return true;
else
return false;
}
void erase_x(int cod, int x)
{
it = find(h[cod].begin(), h[cod].end(), x);
h[cod].erase(it);
}
int main()
{
int n, i, k, x, cod;
fin>>n;
for(i=1;i<=n;i++)
{
fin>>k>>x;
cod = fhash(x);
if(k==1)///adaug elemetul
{
if(find_x(cod, x)==0)
h[cod].push_back(x);
continue;
}
if(k==2)
{
if(find_x(cod, x)==1)
erase_x(cod, x);
continue;
}
if(k==3)
{
if(find_x(cod, x) == 1)
fout<<"1"<<"\n";
else
fout<<"0"<<"\n";
}
}
return 0;
}