Pagini recente » Cod sursa (job #1793400) | Cod sursa (job #348869) | Cod sursa (job #2004284) | Istoria paginii runda/marcel1 | Cod sursa (job #1308949)
#include <vector>
#define NMAX 666013
using namespace std;
class Hash
{
private:
vector <int> v[NMAX];
int size;
int hash(int key)
{
return key%size;
}
public:
Hash()
{
size=NMAX;
}
void insert(int key)
{
int h=hash(key);
for(int i=0;i<v[h].size();i++)
if(v[h][i]==key) return;
v[h].push_back(key);
}
bool lookup(int key)
{
int h=hash(key);
for(int i=0;i<v[h].size();i++)
if(v[h][i]==key) return 1;
return 0;
}
void del(int key)
{
int h=hash(key);
for(int i=0;i<v[h].size();i++)
if(v[h][i]==key)
{
v[h][i]=v[h][v[h].size()-1];
v[h].pop_back();
return;
}
}
}H;
#include <fstream>
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int main()
{
int N,q,x;
f>>N;
while(N--)
{
f>>q>>x;
switch(q)
{
case 1:H.insert(x); break;
case 2:H.del(x); break;
case 3:g<<H.lookup(x)<<'\n'; break;
}
}
}