Cod sursa(job #2121385)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 3 februarie 2018 17:15:31
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.09 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

int mod = 123457;
vector <int> v[123458];

inline int CautareElement(int x)
{
    int i,R = x%mod;
    for (i=0; i<v[R].size(); i++)
    {
        if (v[R][i] == x)
            return 1;
    }
    return 0;
}

void Adauga(int x)
{
    int R = x%mod;
    if (CautareElement(x) == 0)
    {
        v[R].push_back(x);
    }
}

void Sterge(int x)
{
    int R = x%mod,j,ok = 0;
    if(CautareElement(x) == 1)
    {
        for (j=0; j<v[R].size() && ok == 0; j++)
            if (v[R][j] == x)
              {
                  ok = 1;
                  v[R][j] = v[R][v[R].size() - 1];

              }
         v[R].pop_back();
    }
}


int main()
{
    int n,i,tip,x;
    in >> n;
    for (i=1; i<=n; i++)
    {
        in >> tip >> x;
        if (tip == 1)
            Adauga(x);
        if (tip == 2)
            Sterge(x);
        if (tip == 3)
            out << CautareElement(x) << "\n";
    }
    return 0;
}