Pagini recente » Cod sursa (job #2045993) | Cod sursa (job #682166) | Cod sursa (job #1757777) | Cod sursa (job #2704045) | Cod sursa (job #963247)
Cod sursa(job #963247)
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<vector>
#define N 44497
using namespace std;
template<typename Tkey> class Hashtable {
private:
vector<unsigned int> H[N];
public:
void put(Tkey key)
{
if(!hasKey(key))
{
unsigned int poz;
poz = key % N;
H[poz].push_back(key);
}
}
bool hasKey(Tkey key)
{
unsigned int poz;
poz = key % N;
vector<unsigned int>::iterator it;
for(it = H[poz].begin(); it != H[poz].end(); ++it)
if(*it == key)
return true;
return false;
}
void remove(Tkey key)
{
unsigned int poz = key % N;
vector<unsigned int>::iterator it;
for(it = H[poz].begin(); it != H[poz].end(); ++it)
if(*it == key)
{
H[poz].erase(it);
return;
}
}
};
int main()
{
unsigned int n;
short int op;
unsigned int x;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &n);
Hashtable<unsigned int> hash;
for(unsigned int i = 0; i < n; i++)
{
scanf("%hd", &op);
scanf("%d", &x);
if(op == 1)
hash.put(x);
else if(op == 2)
hash.remove(x);
else
printf("%d\n", hash.hasKey(x));
}
}