Cod sursa(job #605611)

Utilizator PatrunjeluMarginean Bogdan Alexandru Patrunjelu Data 1 august 2011 13:12:59
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.46 kb
#include <stdio.h>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;

int n;

vector<long> vec[99999];
ofstream out ("hashuri.out", ofstream::out);

inline int hash(int val)
{
    return val % 10000;
}

inline void add(int val)
{
    int poz = hash(val);
    vec[poz].push_back(val);
}

vector<long>::iterator find(int val)
{
    int poz = hash(val);
    vector<long>::iterator it;
    for (it = vec[poz].begin(); it != vec[poz].end(); ++it)
    {
        if (*it == val)
        {
            return it;
        }
    }
    return vec[poz].end();
}

inline void del(int val)
{
    vector<long>::iterator it = find(val);
    int poz = hash(val);
    if (it != vec[poz].end())
    vec[poz].erase(it);
}

void findd(int val)
{
    int poz = hash(val);
    vector<long>::iterator it = find(val);
    if (it != vec[poz].end())
    out << 1 << endl;
    else
    out << 0 << endl;
}

int main()
{
    //freopen("hashuri.in", "r", stdin);
    //freopen("hashuri.out", "w", stdout);
   // scanf("%d", &n);
    ifstream in("hashuri.in", ifstream::in);
    in >> n;
    int op, param;
    for (int i = 0; i < n; ++i)
    {
       // scanf("%d%d", &op, &param);
        in >> op >> param;
        switch(op)
        {
            case(1): add(param); break;
            case(2): del(param); break;
            case(3): findd(param); break;
        }
    }
    in.close();
    out.close();
    return 0;
}