Cod sursa(job #605607)

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

int n;

vector<long> vec[999];

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

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())
    printf("%d\n", 1);
    else
    printf("%d\n", 0);
}

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