Mai intai trebuie sa te autentifici.
Cod sursa(job #2308952)
Utilizator | Data | 28 decembrie 2018 03:38:17 | |
---|---|---|---|
Problema | Hashuri | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 1.03 kb |
#include<iostream>
#include<fstream>
#include<vector>
#define PRIME_NUMBER 123457
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
vector <int> L[123457];
void Add(int nr)
{
int key = nr % PRIME_NUMBER;
int found = 0;
for (int j = 0; j < L[key].size() && found == 0; j++)
if (L[key][j] == nr)
found = 1;
if (found == 0)
L[key].push_back(nr);
}
void Remove(int nr)
{
int key = nr % PRIME_NUMBER;
int found = 0;
for (int j = 0; j < L[key].size(); j++)
if (L[key][j] == nr)
{
L[key][j] = L[key][L[key].size()-1];
L[key].pop_back();
}
}
int Search(int nr)
{
int key;
key = nr % PRIME_NUMBER;
int found = 0;
for (int j = 0; j < L[key].size(); j++)
if (L[key][j] == nr)
return 1;
return 0;
}
int main ()
{
int T;
fin >> T;
int i, nr, type;
for (i = 0; i < T; i++)
{
fin >> type >> nr;
if (type == 1) Add(nr);
else if (type == 2) Remove(nr);
else if (type == 3) fout << Search(nr) << "\n";
}
return 0;
}