Cod sursa(job #1950647)

Utilizator seby2341Mesca Sebastian seby2341 Data 3 aprilie 2017 10:43:00
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>
#include <vector>
#define IN_FILE "hashuri.in"
#define OUT_FILE "hashuri.out"
#define pb push_back
#define MOD 666013
using namespace std;
ifstream fin(IN_FILE);
ofstream fout(OUT_FILE);
int x,op,i,n,ind;
vector <int> h[MOD];
vector <int> :: iterator it;

vector <int>  :: iterator search_x(int x)
{
    for ( it=h[ind].begin(); it!=h[ind].end(); it++)
        if (*it==x) return it;
    return it;

}
void insert_x (int x)
{
    if (it==h[ind].end()) h[ind].pb(x);
}
void erase_x (int x)
{
    if (it!=h[ind].end()) h[ind].erase(it);

        }
void write_x(int x)
{
    if (it==h[ind].end()) fout<<0<<'\n';
    else fout<<1<<'\n';

}
int main()
{
    fin>>n;
    for (int i=1; i<=n; i++)
    {
        fin>>op>>x;
        ind=x%MOD;
        it=search_x(x);
        if (op==1) insert_x(x);
        if (op==2) erase_x(x);
        if (op==3) write_x(x);
    }
    return 0;
}