Cod sursa(job #2790534)

Utilizator Durlesteanu_VictorDurlesteanu Victor Durlesteanu_Victor Data 29 octombrie 2021 10:40:20
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <bits/stdc++.h>
#define P 8191
using namespace std;
/**
Tabele de hash - Tabele de dispersie

P = 7
1..100

38

h[0] = 7, 14, 21, 28
h[1] = 8, 15, 22,...
h[2] =
            i
h[3] = 10, 17, 24, 31, 38
h[4] =
h[5] =
h[6] = 13,20,27,...

*/

vector<int> h[P];

void Sterge(int x)
{
    int r = x % P;
    int L = h[r].size();
    for (int i = 0; i < L; i++)
        if (h[r][i] == x)
        {
            h[r][i] = h[r][L-1];
            h[r].pop_back();
            return;
        }
}

void Adauga(int x)
{
    int r = x % P;
    h[r].push_back(x);
}

int Cauta(int x)
{
    int r = x % P;
    for (int e : h[r])
        if (e == x) return 1;
    return 0;
}

/**
Se da un sir a1, a2, ..., an. Sa se verifice daca exista doua
elemente egale in sir.
8
1 5 2000000000 17 5 2 18 3
*/

unordered_map<int, bool> M;

int main()
{
    int i, x, n;
/**
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        if (Cauta(x) == 1)
        {
            cout << "Am gasit pe " << x;
            return 0;
        }
        Adauga(x);
    }
    cout << "Toate sunt distincte";
*/
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        if (M[x] == true)
        {
            cout << x;
            return 0;
        }
        M[x] = true;
    }
    cout << "Toate sunt distincte";
    return 0;
}