Cod sursa(job #2896580)

Utilizator bianca2002Bianca bianca2002 Data 29 aprilie 2022 23:51:02
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <fstream>
#include <iostream>
#include <list>

using namespace std;

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

const int nr = 666013;

list <int> vect[nr];

bool verifica(int x, int poz)
{
    for(auto i = vect[poz].begin(); i!=vect[poz].end(); i++)
        if(*i == x) return 1;
     return 0;
}

void adauga(int x, int poz)
{
    if (!verifica(x, poz))
        vect[poz].push_back(x);
}

void sterge(int x, int poz)
{
    for(auto i=vect[poz].begin(); i!=vect[poz].end(); i++)
    {
        if(*i==x)
        {
            vect[poz].erase(i);
            break;
        }
    }
}

int main()
{
    int n, i, x, opt;

    f>>n;

    for(i=0;i<n;i++)
    {
        f>>opt>>x;
        if(opt==1)
        {
            adauga(x, x%nr);
        }
        else if(opt==2)
        {
            sterge(x, x%nr);
        }
        else if(opt==3)
        {
            g<<verifica(x, x%nr)<<endl;
        }
    }
}