Cod sursa(job #2742117)

Utilizator vladalex420@gmail.comLuta Vlad Alexandru [email protected] Data 20 aprilie 2021 11:35:10
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.33 kb
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <utility>
#include <vector>
#include <unordered_map>

#include <fstream>
#include <stdio.h>

#include <iostream>
#include <list>

struct HashMap
{
	static constexpr int P = 11587; //a big prime number

	std::list<int> elements[P];
	
	void addElement(int el)
	{
		int index = el % P;
		if( std::find(elements[index].begin(), elements[index].end(), el) == elements[index].end() )
		{
			elements[index].push_back(el);
		}
		//elements[index].insert(el);
	}
	
	void removeElement(int el)
	{
		int index = el % P;
		elements[index].remove(el);
	}

	int isElement(int el)
	{
		int index = el % P;
		if (std::find(elements[index].begin(), elements[index].end(), el) != elements[index].end())
		{
			return 1;
		}
		else
		{
			return 0;
		};

	}

};


int main()
{
	
	std::ifstream in("hashuri.in");
	std::ofstream out("hashuri.out");

	if(!in.is_open())
	{
		return 0;
	}

	HashMap hashMap;

	int n = 0;
	in >> n;

	for (int i = 0; i < n; i++)
	{
		int op, val;
		in >> op >> val;

		if(op == 1)
		{
			hashMap.addElement(val);
		}else
		if(op == 2)
		{
			hashMap.removeElement(val);
		}else
		if(op == 3)
		{
			out << hashMap.isElement(val) << "\n";
		}

	}
	
	in.close();
	out.close();

	return 0;
}