Pagini recente » Borderou de evaluare (job #180214) | Monitorul de evaluare | Cod sursa (job #426755) | Borderou de evaluare (job #2929020) | Cod sursa (job #1324908)
using namespace std;
#define NULL 0
#define NMAX 666013
#include <vector>
class Hash
{
private:
vector <int> v[NMAX];
int size;
int hash(int x)
{
return (x%size);
}
public:
Hash()
{
size=NMAX;
}
bool lookup(int x)
{
int h=hash(x),i;
for(i=0;i<v[h].size();i++)
if(v[h][i]==x) return 1;
return 0;
}
void insert(int x)
{
if(lookup(x)) return;
int h=hash(x);
v[h].push_back(x);
}
void del(int x)
{
int h=hash(x),i;
for(i=0;i<v[h].size();i++)
if(v[h][i]==x)
{
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 T;
f>>T;
int q,x;
while(T--)
{
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;
}
}
}