Pagini recente » Cod sursa (job #1665819) | Cod sursa (job #2841716) | Cod sursa (job #2119261) | Cod sursa (job #1557483) | Cod sursa (job #1481464)
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
typedef unsigned int tip;
const tip mod = 1365011, pHas = 661;
tip N;
vector <tip> Vec[mod];
int hash(int a){
return ( (a * pHas) % mod );
}
void inserare(tip x){
Vec[ hash(x) ].push_back(x);
}
void stergere(tip x){
tip pozitie = hash(x);
for( int i = 0; i < Vec[pozitie].size(); ++i )
if( Vec[pozitie][i] == x)
Vec[pozitie].erase( Vec[pozitie].begin() + i);
}
bool cautare(tip x){
tip pozitie = hash(x);
for( int i = 0; i < Vec[pozitie].size(); ++i )
if( Vec[pozitie][i] == x )
return 1;
return 0;
}
int main(){
tip x, val;
f>>N;
for(tip i = 1; i <= N; ++i){
f>>val>>x;
switch(val){
case 1:inserare(x); break;
case 2:stergere(x); break;
case 3:g<<cautare(x)<<'\n'; break;
}
}
return 0;
}