Pagini recente » Cod sursa (job #2982918) | Istoria paginii runda/bomba1/clasament | Cod sursa (job #203966) | Cod sursa (job #693884) | Cod sursa (job #1775395)
#include<fstream>
#include<vector>
#define modulo 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector<int> v[666013];
int cauta(int number)
{
int gasit = 0, hashKey = number % modulo;
int i;
for(i = 0;i <v[hashKey].size(); i++)
{
if(v[hashKey][i] == number)
{
return 1;
}
}
return 0;
}
void adauga(int number)
{
int hashKey = number % modulo;
if(cauta(number) == 0)
{
v[hashKey].push_back(number);
}
}
void sterge(int number)
{
int hashKey = number % modulo, i;
int pozition = -1;
for(i = 0;i < v[hashKey].size();i++)
{
if(v[hashKey][i] == number)
{
pozition = i;
break;
}
}
if(pozition != -1)
{
v[hashKey].erase(v[hashKey].begin() + pozition);
}
}
int main()
{
int n, i, caz, number;
fin >> n;
for(i = 1; i <= n; i++ )
{
fin>> caz >> number;
if(caz == 1)
{
adauga(number);
}
if(caz == 2)
{
sterge(number);
}
if(caz ==3)
{
fout << cauta(number) <<"\n";
}
//fout<<caz<<" ";
}
}