Cod sursa(job #1855345)

Utilizator AndreidgDragomir Andrei Valentin Andreidg Data 23 ianuarie 2017 16:30:11
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.2 kb
#include <fstream>
#include <vector>
using namespace std;
const int MOD=666013;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> v[MOD];
int n,op,val;
bool exist(int x)
{
    int cod;
    cod=x%MOD;
    vector <int> ::iterator it;

    for(it=v[cod].begin();it!=v[cod].end();it++)
    {
        if(*it==x)
            return true;
    }
    return false;
}
void del(int x)
{
    int cod;
    cod=x%MOD;
    vector <int> ::iterator it;

    for(it=v[cod].begin();it!=v[cod].end();it++)
    {
        if(*it==x)
        {
            v[cod].erase(it);
            return;
        }
    }

}
void ins(int x)
{
    int cod;
    cod=x%MOD;
    vector <int> ::iterator it;

    for(it=v[cod].begin();it!=v[cod].end();it++)
    {
        if(*it==x)
        {
            return;
        }
    }
    v[cod].push_back(x);
}
int main()
{
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>op>>val;
        if(op==1)
        {
            ins(val);
        }
        if(op==2)
        {
            del(val);
        }
        if(op==3)
        {
            g<<exist(val)<<"\n";
        }
    }
    f.close();
    g.close();
    return 0;
}