Cod sursa(job #2243336)

Utilizator ptudortudor P ptudor Data 20 septembrie 2018 12:28:03
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>
using namespace std;
const int P=99991;
int n;
vector <int> h[P];
void adaug(int x);
void sterg(int x);
int caut(int x);
int main()
{int i,p,x;
    ifstream in("hashuri.in");
    ofstream out("hashuri.out");
    in>>n;
    for (i=1;i<=n;i++)
    {in>>p>>x;
    if (p==1)
        adaug(x);
    if (p==2)
        sterg(x);
    if (p==3)
        out<<caut(x)<<"\n";
    }

}
void adaug(int x)
{
    int r=x%P,i,gasit=0;
    for (i=0;i<h[r].size()&&gasit==0;i++)
      if (h[r][i]==x)
        gasit=1;
    if (gasit==0)
        h[r].push_back(x);
}
void sterg(int x)
{
    int r=x%P,i,gasit=0;
    for (i=0;i<h[r].size()&&gasit==0;i++)
        if (h[r][i]==x)
        {
            gasit=1;
            h[r][i]=h[r][h[r].size()];
            h[r].pop_back();
        }
}
int caut(int x)
{
    int r=x%P,i;
    for (i=0;i<h[r].size();i++)
        if (h[r][i]==x)
            return 1;
    return 0;
}