Cod sursa(job #1481477)

Utilizator adiXMGemene Adrian adiXM Data 4 septembrie 2015 16:29:38
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <fstream>
#include <vector>
using namespace std;
const int MOD=100003;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct Hash{
    vector <int> V[MOD];
    void Adauga(const int x){
        if(Cauta(x))
            return;
        V[x%MOD].push_back(x);
    }
    bool Cauta(int x){
        int rest=x%MOD;
        for(vector<int>::iterator it=V[rest].begin();it!=V[rest].end();it++)
            if(*it==x)
                return 1;
        return 0;
    }
    void Sterge(const int x){
        int rest=x%MOD;
        int size=V[rest].size();
        for(int i=0;i<size;i++)
            if(V[rest][i]==x)
            {
                V[rest][i]=V[rest][size-1];
                V[rest].pop_back();
                return;
            }

    }
};
Hash H;
int main()
{
    int n,x,op;
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>op>>x;
        if(op==1)
            H.Adauga(x);
        else
            if(op==2)
                H.Sterge(x);
        else
            g<<H.Cauta(x)<<"\n";
    }
    return 0;
}