Cod sursa(job #726115)

Utilizator ssergiussSergiu-Ioan Ungur ssergiuss Data 27 martie 2012 00:29:31
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.32 kb
#include <algorithm>
#include <fstream>
#include <vector>

using namespace std;

#define MOD 666013

int nOperations;
vector <int> hash[MOD];

bool isIn(int element) {
    bool isOk;
    int mod;

    mod = element % MOD;
    isOk = find(hash[mod].begin(), hash[mod].end(), element) != hash[mod].end();

    return isOk;
}

void add(int element) {
    int mod;

    if (!isIn(element)) {
        mod = element % MOD;
        hash[mod].push_back(element);
    }
}

void remove(int element) {
    int mod;
    vector<int>::iterator it;

    if (isIn(element)) {
        mod = element % MOD;
        it = find(hash[mod].begin(), hash[mod].end(), element);
        hash[mod].erase(it);
    }
}

int main() {
    ifstream fin ("hashuri.in" );
    ofstream fout("hashuri.out");

    int element, operation;

    fin >> nOperations;
    while (nOperations--) {
        fin >> operation;
        switch (operation) {
            case 1 :
                fin >> element;
                add(element);
                break;

            case 2 :
                fin >> element;
                remove(element);
                break;

            case 3 :
                fin >> element;
                fout << isIn(element) << "\n";
                break;
        }
    }

    return 0;
}