Pagini recente » Cod sursa (job #102419) | Cod sursa (job #2436862) | Cod sursa (job #1841150) | Cod sursa (job #1475062) | Cod sursa (job #3231370)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
///hashuri
class Hash
{
public:
int n;
list<int> *H;
Hash(int n)
{
this->n = n;
H = new list<int>[n+5];
}
~Hash()
{
delete []H;
}
int Modulo(int x)
{
return x % n;
}
void Insert(int x)
{
int index = Modulo(x);
H[index].push_back(x);
}
void Delete(int x)
{
int index = Modulo(x);
list <int> :: iterator it;
for (it = H[index].begin(); it != H[index].end() && *it != x; it++)
;
if(it != H[index].end()) H[index].erase(it);
}
void Afisare()
{
int i;
for (i = 0; i < n; i++)
{
for (auto w : H[i])
fout << w << " ";
fout << "\n";
}
}
bool Find(int x)
{
int index = Modulo(x);
list<int>::iterator it;
for (it = H[index].begin(); it != H[index].end(); it++)
if (*it == x) return true;
return false;
}
};
int main()
{
Hash A(1234577);
int op, n, i, x;
fin >> n;
for(i=1; i<=n; i++)
{
fin >> op >> x;
if(op == 1) A.Insert(x);
else if(op == 2) A.Delete(x);
else fout << A.Find(x) << "\n";
}
return 0;
}