Pagini recente » Cod sursa (job #1760563) | Cod sursa (job #2455752) | Cod sursa (job #1365831) | Cod sursa (job #1179842) | Cod sursa (job #2762079)
#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
#define HASH 999983
ifstream fin("hashuri.in.txt");
ofstream fout("hashuri.out.txt");
int N;
vector<int> LISTE[HASH]; // array of 999983 vectors
bool Find(int x)
{
vector<int>::iterator it;
int hashPos = x % HASH;
for(it = LISTE[hashPos].begin(); it!= LISTE[hashPos].end(); ++it)
if( (*it) == x){return 1;}
return 0;
}
void Insert(int x)
{
if(Find(x) == 0)
{
int hashPos = x % HASH;
LISTE[hashPos].push_back(x);
}
}
void Erase(int x)
{
int hashPos = x % HASH;
for(int i = 0; i < LISTE[hashPos].size(); ++i)
{
if( LISTE[hashPos][i] == x)
LISTE[hashPos].erase(LISTE[hashPos].begin()+i);
}
}
int main()
{
int n, op, x;
fin>>n;
for(int i = 0; i< n; ++i)
{
fin>>op>>x;
if(op == 1) {Insert(x); continue;}
if(op == 2) {Erase(x);continue;}
if(op==3) {fout<<Find(x)<<'\n'; continue;}
}
return 0;
}