Cod sursa(job #714373)

Utilizator blk.irineluIrina Ursateanu blk.irinelu Data 15 martie 2012 18:17:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include<vector>
#include<fstream>
#define Mod 666013

using namespace std;

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

int n;

class hash
{
    private:
       vector <int> a[Mod];
       int size_of_hash;
    public:
       hash(int size)
       {
           size_of_hash=size;
       }
       void insereaza(int x);
       void sterge(int x);
       void cauta(int x);
};

void hash::insereaza(int x)
{
    int i;
    bool ok=0;
    for(i=0;i<a[x%Mod].size();i++)
     if(a[x%Mod][i]==x) ok=1;
    if(ok==0) a[x%Mod].push_back(x);
}

void hash::sterge(int x)
{
    int i;
    for(i=0;i<a[x%Mod].size();i++)
     if(a[x%Mod][i]==x) a[x%Mod].erase(a[x%Mod].begin()+i);
}

void hash::cauta(int x)
{
    int i;
    bool ok=0;
    for(i=0;i<a[x%Mod].size();i++)
     if(a[x%Mod][i]==x) ok=1;
    g<<ok<<"\n";
}
int main()
{
    int i,op,y;
    f>>n;
    hash object(Mod);
    for(i=1;i<=n;i++)
    {
        f>>op>>y;
        if(op==1) object.insereaza(y);
        if(op==2) object.sterge (y);
        if(op==3) object.cauta(y);
    }

    return 0;
}