Cod sursa(job #2895169)

Utilizator Bogdan197Putineanu Bogdan Bogdan197 Data 28 aprilie 2022 19:52:21
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>
#include <vector>

using namespace std;

const int hash_size = 54767;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int tip_operatie, valoare, nr_operatii;
vector<int> hashtable[hash_size];


int main()
{
	f >> nr_operatii;
	for (int i = 0; i < nr_operatii; i++)
	{
		f >> tip_operatie >> valoare;
		int hash_value = valoare % hash_size;
		if (tip_operatie == 1)
			hashtable[hash_value].push_back(valoare);
		else if (tip_operatie == 2)
		{
			for (int index = 0; index < hashtable[hash_value].size(); index++)
				if (hashtable[hash_value][index] == valoare)
					hashtable[hash_value].erase(hashtable[hash_value].begin() + index);
		}
		else if (tip_operatie == 3)
		{
			int found = 0;
			for (auto const& iterator : hashtable[hash_value])
				if (iterator == valoare)
				{
					g << 1 << endl;
					found = 1;
					break;
				}
			if (!found)
				g << 0 << endl;
		}
	}
}