Cod sursa(job #3159509)

Utilizator ayannnnAyan Sorouri-Amoughin ayannnn Data 21 octombrie 2023 14:33:16
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int b=41;
const int modulo=111119;

int hsh(int numar){
    int s=0;
    while(numar){
        s=(s*b+numar%10)%modulo;
        numar/=10;
    }
    return s;
}

vector<vector<int> >H;

int main()
{

    int n,x,op;
    H.resize(modulo+1);
    f>>n;
    for(int i=0; i<n; i++)
    {
        f>>op>>x;
        int Hash=hsh(x);
        vector<int>::iterator it=find(H[Hash].begin(),H[Hash].end(),x);
        if(op==1 && it==H[Hash].end())
        {
            H[Hash].push_back(x);
        }
        else if(op==2 && it!=H[Hash].end())
        {
            H[Hash].erase(it);
        }
        else if (op==3)
        {
            if(it != H[Hash].end())
                g<<1<<"\n";
            else
                g<<0<<"\n";
        }
    }
    return 0;
}