Pagini recente » Cod sursa (job #2139963) | Cod sursa (job #2921117) | Cod sursa (job #1687912) | Cod sursa (job #2273807) | Cod sursa (job #1247796)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
#define PRIME_MAX 104729
std::vector<int> hash_table[PRIME_MAX];
int getHash(int val)
{
return val % PRIME_MAX;
}
void InsertElement(int num)
{
std::vector<int> &list = hash_table[getHash(num)];
std::vector<int>::iterator it = std::find(list.begin(), list.end(), num);
if (it == list.end())
{
list.push_back(num);
}
}
void RemoveElement(int num)
{
std::vector<int> &list = hash_table[getHash(num)];
std::vector<int>::iterator it = std::find(list.begin(), list.end(), num);
if (it != list.end())
{
list.erase(it);
}
}
int FindElement(int num)
{
std::vector<int> &list = hash_table[getHash(num)];
std::vector<int>::iterator it = std::find(list.begin(), list.end(), num);
if (it == list.end())
{
return 0;
}
else
{
return 1;
}
}
int main()
{
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n;
f >> n;
for (int i = 0; i < n; i++)
{
int com, arg;
f >> com >> arg;
if (com == 1)
InsertElement(arg);
else if (com == 2)
RemoveElement(arg);
else if (com == 3)
g << FindElement(arg) << endl;
}
return 0;
}