Cod sursa(job #1262416)

Utilizator Laura.miLaura Mitrache Laura.mi Data 13 noiembrie 2014 10:13:22
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

vector <int> L[10004];
int n;
int p = 10003;

void Add_hash(int x)
{
    int poz;
    poz = x%p;
    L[poz].push_back(x);
}

void Del_hash(int x)
{
    int poz;
    poz = x%p;
    swap(L[poz][x],L[poz][L[poz].size()-1]);
    L[poz].pop_back();
}

int Hash(int x)
{
    int poz,i;
    poz = x%p;
    for(i=0;i<L[poz].size();i++)
    if(L[poz][i] == x )
    return 1;
    return 0;
}

int main()
{
    int i,x,op;
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>op>>x;
        if(op == 1)
        {
            if(Hash(x) == 0) Add_hash(x);
           // cout<<"A";
        }
        else if(op == 2)
        {
            if(Hash(x) == 1) Del_hash(x);
           // cout<<"D";
        }
        else if (op == 3) cout<<Hash(x)<<"\n";

    }
    return 0;
}