Cod sursa(job #2746750)

Utilizator andreinovaNacu Andrei Emilian andreinova Data 28 aprilie 2021 13:37:39
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.15 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("hashuri.in");
ofstream out("hashuri.out");

const int prim = 50021;

vector<int> v[prim];
int n, c, nr;

void adauga(int x)
{
    v[x % prim].push_back(x);
}

void sterge(int x)
{
    vector<int>::iterator i;

    for(i=v[x % prim].begin(); i!=v[x % prim].end(); i++)
    {
        if(*i == x)
            break;
    }

    if(i != v[x % prim].end())
        v[x % prim].erase(i);
}

void cauta(int x)
{
    vector<int>::iterator i;

    for(i = v[x % prim].begin(); i!=v[x % prim].end(); i++)
        if(*i == x)
            break;

    if(i != v[x % prim].end())
        out << 1<<'\n';

    else out << 0 << '\n';
}

int main()
{
    in>>n;

    for(int i = 0; i < n; i++)
    {
        in>>c>>nr;

        switch(c)
        {
        case 1:
            {
                adauga(nr);
                break;
            }
        case 2:
            {
                sterge(nr);
                break;
            }
        case 3:
            {
                cauta(nr);
                break;
            }
        }
    }
    return 0;
}