Pagini recente » Cod sursa (job #1882109) | Cod sursa (job #619758) | Cod sursa (job #731196) | Cod sursa (job #2565424) | Cod sursa (job #1758531)
#include <cstdio>
#include <algorithm>
#include <vector>
//#include <forward_list>
FILE* in = fopen("hashuri.in", "r");
FILE* out = fopen("hashuri.out", "w");
using namespace std;
vector <long> v;
//vector <vector<long>::iterator> rep;
short check (long x)
{
/*
vector<long>::const_iterator i = find(v.begin(), v.end(), x);
if (i == v.end())
{
return 0;
}
return 1;
*/
return binary_search(v.begin(), v.end(), x);
}
short add (long x)
{
if (check(x) == 0)
{
v.push_back(x);
return 0;
}
return 1;
}
short del (long x)
{
vector<long>::iterator i = find(v.begin(), v.end(), x);
if (i != v.end())
{
v.erase(i);
return 0;
}
return 1;
}
int main()
{
/* debug
*add(3);
*add(5);
*add(10);
*del(5);
*add(15);
*vector<long>::iterator i = v.begin();
*for( ; i < v.end(); i++)
*{
* fprintf(out, "%i ", *i);
*}
*/
v.reserve(1000000);
long i = 0;
short cmd = 0;
long arg = 0;
fscanf(in, "%li", &i);
for (long y = 0; y < i; y++)
{
fscanf(in, "%hi %li", &cmd, &arg);
switch (cmd)
{
case 1:
add(arg);
break;
case 2:
del(arg);
break;
case 3:
//v.unique();
fprintf(out, "%hi\n", check(arg));
break;
default:
printf("ERROR: Unknown command %i!", cmd);
break;
}
}
fclose(in);
fclose(out);
return 0;
}