Cod sursa(job #3129362)

Utilizator iordyIordache Andrei Tudor iordy Data 14 mai 2023 02:29:15
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.23 kb
#include <iostream>
#include <fstream>
#include <list>
#include <vector>

using namespace std;

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

void insert(list <int> *hashTable, int key, int m)
{
    int index = key % m;
    hashTable[index].push_back(key);
}


void deleteElement(list <int> *hashTable, int key, int m)
{
    int index = key % m;
    hashTable[index].remove(key);
}




bool findElement(list <int> *hashTable, int key, int m)
{
    int index = key % m;
    for (auto it = hashTable[index].begin(); it != hashTable[index].end(); it++)
    {
        if (*it == key)
        {
            return true;
        }
    }
    return false;
}


int main(){

    int n;
    fin >> n;

    int m = 666013;

    list <int> *hashTable = new list <int>[m];

    for(int i=0;i<n;i++)
    {
        int optiune;
        fin>>optiune;
        if(optiune == 1)
        {
            int x;
            fin>>x;
            insert(hashTable, x, m);
        }
        if(optiune == 2)
        {
            int x;
            fin>>x;
            deleteElement(hashTable, x, m);
        }
        if(optiune == 3)
        {
            int x;
            fin>>x;
            fout<<findElement(hashTable, x, m)<<"\n";
        }
    }




    return 0;
}