Pagini recente » Cod sursa (job #2065037) | Cod sursa (job #2412009) | Cod sursa (job #854600) | Cod sursa (job #282263) | Cod sursa (job #2746964)
#include<iostream>
#include<fstream>
#include<vector>
#define primeNumber 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector<int> hashTable[primeNumber];
int hashingFunction(int key)
{
return key % primeNumber;
}
void insert(int hashValue, int key)
{
for (int i = 0; i < hashTable[hashValue].size(); i++)
{
if (hashTable[hashValue][i] == key)
{
return;
}
}
hashTable[hashValue].push_back(key);
}
void removing(int hashValue, int key)
{
for (int i = 0; i < hashTable[hashValue].size(); i++)
{
if (hashTable[hashValue][i] == key)
{
hashTable[hashValue].erase(hashTable[hashValue].begin() + i);
}
}
}
int ifExists(int hashValue, int key)
{
int answer = 0;
for (int i = 0; i < hashTable[hashValue].size(); i++)
{
if (hashTable[hashValue][i] == key)
{
answer = 1;
}
}
return answer;
}
int main()
{
int N, key;
unsigned int operation;
fin >> N;
for (int i = 0; i < N; i++)
{
fin >> operation;
switch (operation)
{
case 1:
{
fin >> key;
insert(hashingFunction(key), key);
} break;
case 2:
{
fin >> key;
removing(hashingFunction(key), key);
} break;
default:
{
fin >> key;
fout << ifExists(hashingFunction(key), key) << "\n";
} break;
}
}
}