Cod sursa(job #1596104)

Utilizator dimavascan94VascanDumitru dimavascan94 Data 10 februarie 2016 20:00:36
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
int N, op, x,size = 0;

int main()
{
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	cin >> N;
	int * hash = (int*)malloc(N * 4);
	memset(hash, 0, N * 4);
	while (N > 0)
	{
		cin >> op >> x;
		bool exists = false;
		int pos = -1;
		switch (op)
		{
			case 1://insert value, if does not exist
				for (int i = 0; i < size && !exists; ++i)
				{
					exists = (hash[i] == x);
				}

				if (!exists)
				{
					hash[size++] = x;
				}
				break;
			case 2://delete value, if exists
				for (int i = 0; i < size && !exists; ++i)
				{
					exists = (hash[i] == x);
					if (exists)
					{
						hash[i] = 0;
					}
				}
				break;
			case 3://try to find the value, and print output
				for (int i = 0; i < size && !exists; ++i)
				{
					exists = (hash[i] == x);
				}

				cout << exists << "\n";
				break;
		}
		N--;
	}

}