Pagini recente » Cod sursa (job #1750756) | Cod sursa (job #132394) | Cod sursa (job #69744) | Cod sursa (job #2076750) | Cod sursa (job #2040242)
#include <fstream>
#include <vector>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
#define max 333331
vector<int> T[max];
int Hash_Function(int x)
{
return x%max;
}
void Add(int x)
{
int h = Hash_Function(x);
for (auto it = T[h].begin(); it != T[h].end(); it++)
{
if (x == *it)
return;
}
T[h].push_back(x);
}
void Remove(int x)
{
int h = Hash_Function(x);
for (int i = 0; i<T[h].size(); i++)
{
if (x == T[h][i])
{
T[h].erase(T[h].begin() + i);
return;
}
}
}
bool Exists(int x)
{
int h = Hash_Function(x);
for (auto it = T[h].begin(); it != T[h].end(); it++)
{
if (x == *it)
return true;
}
return false;
}
int main()
{
int n;
in >> n;
while (n--)
{
int opt, x;
in >> opt >> x;
switch (opt)
{
case 1:
Add(x);
break;
case 2:
Remove(x);
break;
case 3:
out << (Exists(x) == true ? 1 : 0) << '\n';
break;
}
}
}