Pagini recente » Cod sursa (job #1354883) | Cod sursa (job #19062) | Cod sursa (job #1729794) | Cod sursa (job #1377911) | Cod sursa (job #2895181)
#include <fstream>
#include <vector>
using namespace std;
const int hash_size = 54767;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int tip_operatie, valoare, nr_operatii;
vector<int> hashtable[54767];
int main()
{
f >> nr_operatii;
for (int i = 0; i < nr_operatii; i++)
{
f >> tip_operatie >> valoare;
int hash_value = valoare % hash_size;
if (tip_operatie == 1)
hashtable[hash_value].push_back(valoare);
else if (tip_operatie == 2)
{
for (int index = 0; index < hashtable[hash_value].size(); index++)
if (hashtable[hash_value][index] == valoare)
hashtable[hash_value].erase(hashtable[hash_value].begin() + index);
}
else if (tip_operatie == 3)
{
int found = 0;
for (int index = 0; index < hashtable[hash_value].size() && found == 0;index++)
if (hashtable[hash_value][index] == valoare)
{
g << "1\n";
found = 1;
}
if (!found)
g << "0\n";
}
}
}