Cod sursa(job #1347220)

Utilizator Edsger.DijkstraEdsger Wybe Dijkstra Edsger.Dijkstra Data 18 februarie 2015 20:52:26
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

const int MOD = 666013;

vector <int> H[MOD];

void Insert (int x)
{
    H[x % MOD].push_back (x);
}

void Erase (int x)
{
    vector <int> :: iterator it;

    int now = x % MOD;

    for (it = H[now].begin (); it != H[now].end (); ++ it)
        if (*it == x){
            H[now].erase (it);
            return;
        }
}

bool Find (int x)
{
    vector <int> :: iterator it;

    int now = x % MOD;

    for (it = H[now].begin (); it != H[now].end (); ++ it)
        if (*it == x)
            return 1;

    return 0;
}

int main()
{
    int N, op, x;

    in >> N;
    while (N --){
        in >> op >> x;

        if (op == 1)
            Insert (x);
        if (op == 2)
            Erase (x);
        if (op == 3)
            if (Find (x))
                out << "1\n";
            else
                out << "0\n";
    }
    return 0;
}