Cod sursa(job #1045945)

Utilizator OsDragosNiculai Dragos OsDragos Data 2 decembrie 2013 13:59:27
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
//#include "stdafx.h"
#include <vector>
#include <ostream>
#include <sstream>
#include <fstream>
#include <stdio.h>

using namespace std;
#define MOD 666013
fstream f, g;
vector<int> H[MOD];

int cauta(int val)
{
	int unde = val % MOD;
	vector<int>::iterator it;
    for (it = H[unde].begin(); it != H[unde].end(); ++it)
        if (*it == val)
			return 1;

	return 0;
}

void insert(int val)
{
	int unde = val % MOD;
	H[unde].push_back(val);
}

int sterge(int val)
{
	int unde = val % MOD;
	for(int i = 0; i<H[unde].size(); i++)
		if(H[unde][i]==val)
		{
			H[unde][i]=H[unde].back();
			H[unde].pop_back();
			return 1;
		}
	return 0;	
}

int main()
{
	f.open("hashuri.in", ios::in);
	g.open("hashuri.out", ios::out);

	int n, i, op, x;
	f>>n;
	for(i=1;i<=n;i++)
	{
		f>>op>>x;
		switch(op)
		{
		case 1:
			if(!cauta(x))
				insert(x);
			break;
		case 2:
			if(cauta(x))
				sterge(x);
			break;
		case 3:
			if(cauta(x))
				g<<1<<"\n";
			else
				g<<0<<"\n";
			break;
		}
	}
	f.close();
	g.close();
	return 0;
}