Pagini recente » Cod sursa (job #1290471) | Cod sursa (job #3277695) | Cod sursa (job #3125878) | Cod sursa (job #2338007) | Cod sursa (job #1758515)
#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;
forward_list<long> v;
short check (long x)
{
/*
forward_list<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)
{
v.push_front(x);
return 0;
}
short del (long x)
{
v.remove(x);
return 0;
}
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);
*}
*/
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;
}