Cod sursa(job #2222530)

Utilizator Luca19Hritcu Luca Luca19 Data 17 iulie 2018 10:50:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <fstream>
#include <vector>
#define prim 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n,op,x;
vector <long> Hash[prim];
bool cauta(long x)
{
    int rest=x%prim;
     for(int i = 0; i<Hash[rest].size(); ++i)
    {
        if(Hash[rest][i] == x)
            return 1;
    }
    return 0;
}
void push(long x)
{
    if(cauta(x)==0)
    {
         Hash[x%prim].push_back(x);
    }
}
void sterge(long x)
{
    int rest = x%prim;
    for(int i = 0; i<Hash[rest].size(); ++i)
    {
        if(Hash[rest][i]==x)
        {
            Hash[rest].erase(Hash[rest].begin() + i);
            return;
        }
    }
}
int main()
{
  f>>n;

    while(n--)
    {
        int op;
        long x;
        f>>op;
        f>>x;
        if(op==1)
        {
            push(x);
        }
        else
        if(op==2)
        {
            sterge(x);
        }
        else
        {
            g<<cauta(x)<<'\n';
        }
    }

    return 0;
}