Pagini recente » Cod sursa (job #2694381) | Cod sursa (job #998800) | Cod sursa (job #2675708) | Cod sursa (job #574073) | Cod sursa (job #2617704)
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
class Hash
{
int nr;
vector<int>* tabel;
public:
Hash(int);
void Insert(int);
void Delete(int);
int Find(int);
int hashFuction(int x)
{
return x % nr;
}
};
Hash::Hash(int x)
{
nr = x;
tabel = new vector<int>[nr];
}
void Hash::Insert(int x)
{
int i = hashFuction(x);
tabel[i].push_back(x);
}
void Hash::Delete(int x)
{
int i = hashFuction(x);
vector <int>::iterator j;
for (j = tabel[i].begin(); j != tabel[i].end(); i++)
if (*j == x)
break;
if (j != tabel[i].end())
tabel[i].erase(j);
}
int Hash::Find(int x)
{
int i = hashFuction(x);
vector <int>::iterator j;
for (j = tabel[i].begin(); j != tabel[i].end(); i++)
if (*j == x)
return 1;
return 0;
}
int main() {
int N, x, y;
Hash ob(666013);
fin >> N;
while (N)
{
fin >> x;
if (x == 1)
{
fin >> y;
ob.Insert(y);
}
if (x == 2)
{
fin >> y;
ob.Delete(y);
}
if (x == 3)
{
fin >> y;
fout << ob.Find(y) << "\n";
}
N--;
}
return 0;
}