Mai intai trebuie sa te autentifici.
Cod sursa(job #2773842)
Utilizator | Data | 8 septembrie 2021 21:39:56 | |
---|---|---|---|
Problema | Hashuri | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 1.09 kb |
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> h[769553];
int n, element, operatie, i, cheie, mod = 769553;
void inserare(int element, int cheie)
{
int ok = 1;
for(i=0; i < h[cheie].size(); i++)
if (h[cheie][i]==element)
ok = 0;
if(ok)
h[cheie].push_back(element);
}
void stergere(int element, int cheie)
{
for(i=0; i < h[cheie].size(); i++)
if (h[cheie][i]==element)
h[cheie].erase(h[cheie].begin()+i);
}
int cautare(int element, int cheie)
{
for(i=0; i < h[cheie].size(); i++)
if (h[cheie][i]==element)
return 1;
return 0;
}
int main()
{
f>>n;
for(i = 0; i < n; i++)
{
f>>operatie>>element;
cheie = element % mod;
if (operatie==1)
inserare(element, cheie);
else
if(operatie==2)
stergere(element, cheie);
else
g<<cautare(element, cheie);
}
f.close();
g.close();
return 0;
}