Cod sursa(job #1772431)

Utilizator OFY4Ahmed Hamza Aydin OFY4 Data 6 octombrie 2016 19:07:00
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <fstream>

#define prm 101

using namespace std;

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

const int mod = 1 << 2;
int h[mod], n ,tp, mamaliga;

void son(int &poz)
{
    if(++poz == mod)
        poz = 0;
}

int bul(int x)
{
    int poz = (1LL * x * prm) % mod;

    while(h[poz] != x && h[poz] != 0)
    {
        son(poz);
    }

    if(h[poz] == x)
        return poz;
    else
        return -1;
}

void ekle(int x)
{
    if(bul(x) != 1)
        return;
    int poz = (1LL * x * prm) % mod;

    while(h[poz] != x && h[poz] != 0)
    {
        son(poz);
    }
    h[poz] = x;
}

void sil(int x)
{
    int poz = bul(x);
    if(poz != -1)
    {
        h[poz] = -1;
    }
}

int main()
{
    in >> n;
    for(;n > 0; --n)
    {
        in >> tp >> mamaliga;

        if(tp == 1)
            ekle(mamaliga);
        else if(tp = 2)
            sil(mamaliga);
        else if(bul(mamaliga) == -1)
            out << 0 << "\n";
        else
            out << 1 << "\n";
    }
}