Pagini recente » Cod sursa (job #1653276) | Cod sursa (job #3181808) | Cod sursa (job #12369) | Cod sursa (job #3152221) | Cod sursa (job #678685)
Cod sursa(job #678685)
#include <fstream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
#define M 1666013
#define MaxColez 100
int A[M], N;
int H(int x, int p)
{
return (x%(M-p) + 2*p) % M;
}
void insereaza(int x)
{
int p=0;
while (A[H(x,p)]>0 && A[H(x,p)]!=x) p++;
if (A[H(x,p)]!=x) A[H(x,p)] = x;
}
void sterge(int x)
{
int p=0;
while ((A[H(x,p)] || A[H(x,p)]==-1) && A[H(x,p)]!=x) p++;
if (A[H(x,p)]==x) A[H(x,p)] = -1;
}
bool cauta(int x)
{
int p=0;
while ((A[H(x,p)] || A[H(x,p)]==-1) && A[H(x,p)]!=x) p++;
return A[H(x,p)] == x;
}
int main()
{
int c,x;
f >> N;
for (;N--;){
f >> c >> x;
if (c==1) insereaza(x); else
if (c==2) sterge(x); else
if (c==3) g << cauta(x) << '\n';
}
return 0;
}