Cod sursa(job #1999997)

Utilizator adimiclaus15Miclaus Adrian Stefan adimiclaus15 Data 12 iulie 2017 14:46:21
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> h[MOD];
vector <int>::iterator it;
int i,n,op,x,ind;
vector <int>::iterator cauta_v(int x)
{
    for(it=h[ind].begin();it!=h[ind].end();it++)
    {
        if(*it==x)
        {
            return it;
        }
    }
    return it;
}
void adauga_v(int x)
{
    if(it==h[ind].end())
    {
         h[ind].push_back(x);
    }
}
void sterge_v(int x)
{
    if(it!=h[ind].end())
    {
        h[ind].erase(it);
    }
}
void raspuns_v(int x)
{
    if(it==h[ind].end())
    {
        g<<0<<"\n";
    }
    else
    {
        g<<1<<"\n";
    }
}
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>op>>x;
        ind=x%MOD;
        it=cauta_v(x);
        if(op==1)
        {
            adauga_v(x);
        }
        if(op==2)
        {
            sterge_v(x);
        }
        if(op==3)
        {
            raspuns_v(x);
        }
    }
    return 0;
}