Cod sursa(job #1003296)

Utilizator PlatonPlaton Vlad Platon Data 30 septembrie 2013 11:53:36
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.18 kb
#include <iostream>
#include <fstream>
#include <vector>

#define MOD 666013

using namespace std;

int n;
vector<int> l[MOD];

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

vector<int>::iterator gaseste(int x)
{
    int list = x % MOD;
    vector<int>::iterator it;

    for(it=l[list].begin();it!=l[list].end();it++)
    {
        if(*it==x)
        {
            return it;
        }
    }
    return l[list].end();
}

void adauga(int x)
{
    int list = x % MOD;

    if(gaseste(x) == l[list].end())
        l[list].push_back(x);
}

void sterge(int x)
{
    int list = x % MOD;

    vector<int>::iterator it = gaseste(x);

    if(it!=l[list].end())
    {
        l[list].erase(it);
    }
}

int main(int argc, char** argv)
{
    int op;
    int x;

    f>>n;

    for(int i=0;i<n;i++)
    {
        f>>op;
        f>>x;

        if(op==1)
        {
            adauga(x);
        }
        if(op==2)
        {
            sterge(x);
        }
        if(op==3)
        {
            bool d = gaseste(x) != l[x % MOD].end();
            g<<d<<"\n";
        }
    }

    f.close();
    g.close();

    return 0;
}