Cod sursa(job #1890540)

Utilizator LolkekzorChiorean Tudor Lolkekzor Data 23 februarie 2017 12:31:37
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <list>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

#define myPrime 104729*17

int n, x, i, op;
list<int> myHash[myPrime];

void addHash(int x) {
    myHash[x % myPrime].push_back(x);
}

void remHash(int x) {
    list<int>::iterator it;
    for(it = myHash[x % myPrime].begin() ; *it != x && it != myHash[x % myPrime].end() ; it++);

    if (it != myHash[x % myPrime].end())
        myHash[x % myPrime].erase(it);
}

int prntHash(int x) {
    for(list<int>::iterator it = myHash[x % myPrime].begin() ; it != myHash[x % myPrime].end() ; it++) {
        if (*it == x)
            return 1;
    }
    return 0;
}

int main()
{
    fin>>n;
    for (i = 1 ; i <= n ; i++) {
        fin>>op>>x;
        if (op == 1) {
            addHash(x);
        } else if (op == 2) {
            remHash(x);
        } else {
            fout<<prntHash(x)<<'\n';
        }
    }

    return 0;
}