Cod sursa(job #2896398)

Utilizator bianca2002Bianca bianca2002 Data 29 aprilie 2022 22:40:40
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");

int nrprim = 100019;

vector <int> h[100019];

bool gaseste(int x)
{
    int nr = x % nrprim;

    for(int i = 0; i < h[nr].size(); i++)
        if(h[nr][i] == x) return 1;
    else return 0;
}

void sterge (int x)
{
    int nr = x % nrprim;
    if(gaseste(x))
        for(int i = 0; i < h[nr].size(); i++)
        if(h[nr][i] == x)
    {
        h[nr][i] = -1;
        break;
    }
}


int main()
{

    int n, i, x, k;

    f>>n;

    for(i=0;i<n;i++)
    {
        f>>k>>x;
        if(k==1)
        {
            if(!gaseste(x)) h[x % nrprim].push_back(x);
        }
        else if(k==2)
        {
            sterge(x);
        }
        else g<<gaseste(x)<<endl;
    }

}