Cod sursa(job #1656852)

Utilizator MickeyTurcu Gabriel Mickey Data 19 martie 2016 22:01:15
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include<stdlib.h>
#include<stdio.h>
#include<fstream>
#include<string.h>
#include<vector>
#include<algorithm>
#define KEY 666013
using namespace std;
vector <int> v[KEY];
vector <int> ::iterator it;
int n, i, element, type;
void add(int value)
{
	int el = value%KEY;
	v[el].push_back(value);
}
void remove(int value)
{
	int el = value%KEY;
	for (it = v[el].begin();it != v[el].end();it++)
		if (*it == value)
		{
			v[el].erase(it);
			break;
		}
}
int find(int value)
{
	int el = value%KEY;
	for (it = v[el].begin();it != v[el].end();it++)
		if (*it == value)
			return 1;
	return 0;
}
int main()
{
	ifstream f("hashuri.in");
	ofstream g("hashuri.out");
	f >> n;
	for (i = 1;i <= n;i++)
	{
		f >> type >> element;
		if (type == 1)
			add(element);
		if (type == 2)
			remove(element);
		if (type == 3)
			if (find(element) == 1)
				g << 1 << endl;
			else
				g << 0 << endl;
	}
	return 0;
}