Cod sursa(job #2895150)

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

using namespace std;

const int hash_size = 49157;


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