Pagini recente » Cod sursa (job #1879206) | Istoria paginii runda/winner16/clasament | Cod sursa (job #2036657) | Cod sursa (job #1596104)
#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--;
}
}