Pagini recente » Cod sursa (job #2228702) | Cod sursa (job #283434) | Cod sursa (job #51806) | Cod sursa (job #2958821) | Cod sursa (job #605611)
Cod sursa(job #605611)
#include <stdio.h>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
int n;
vector<long> vec[99999];
ofstream out ("hashuri.out", ofstream::out);
inline int hash(int val)
{
return val % 10000;
}
inline void add(int val)
{
int poz = hash(val);
vec[poz].push_back(val);
}
vector<long>::iterator find(int val)
{
int poz = hash(val);
vector<long>::iterator it;
for (it = vec[poz].begin(); it != vec[poz].end(); ++it)
{
if (*it == val)
{
return it;
}
}
return vec[poz].end();
}
inline void del(int val)
{
vector<long>::iterator it = find(val);
int poz = hash(val);
if (it != vec[poz].end())
vec[poz].erase(it);
}
void findd(int val)
{
int poz = hash(val);
vector<long>::iterator it = find(val);
if (it != vec[poz].end())
out << 1 << endl;
else
out << 0 << endl;
}
int main()
{
//freopen("hashuri.in", "r", stdin);
//freopen("hashuri.out", "w", stdout);
// scanf("%d", &n);
ifstream in("hashuri.in", ifstream::in);
in >> n;
int op, param;
for (int i = 0; i < n; ++i)
{
// scanf("%d%d", &op, ¶m);
in >> op >> param;
switch(op)
{
case(1): add(param); break;
case(2): del(param); break;
case(3): findd(param); break;
}
}
in.close();
out.close();
return 0;
}