Pagini recente » Cod sursa (job #2636826) | Cod sursa (job #947990) | Cod sursa (job #2289860) | Cod sursa (job #2576762) | Cod sursa (job #2670248)
#include <fstream>
#include <vector>
using namespace std;
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
int n;
int cerinta, val;
const int mod = 100003;
vector < int > v[100005];
int Hash (int x)
{
int rez = x % mod;
return rez;
}
void Add (int x)
{
int cod = Hash(x);
bool gasit = false;
for (int i=0; i<v[cod].size() && !gasit; i++)
{
if (v[cod][i] == x)
gasit = true;
}
if (!gasit) v[cod].push_back(x);
}
void Delete (int x)
{
int cod = Hash(x);
bool gasit = false;
int index = 0;
for (int i=0; i<v[cod].size() && !gasit; i++)
{
if (v[cod][i] == x)
{
index = i;
gasit = true;
}
}
if (gasit) v[cod][index] = 0;
}
bool Search (int x)
{
int cod = Hash(x);
for (int i=0; i<v[cod].size(); i++)
{
if (v[cod][i] == x)
return true;
}
return false;
}
int main()
{
f >> n;
for (int i=1; i<=n; i++)
{
f >> cerinta >> val;
if (cerinta == 1) Add(val);
if (cerinta == 2) Delete(val);
if (cerinta == 3) g << Search(val) << "\n";
}
return 0;
}