Cod sursa(job #2762079)

Utilizator PopelEmilBogdanPopel Emil-Bogdan PopelEmilBogdan Data 5 iulie 2021 14:16:38
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.04 kb
#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;

}