Pagini recente » Cod sursa (job #291999) | Cod sursa (job #3149633) | Cod sursa (job #2113638) | Cod sursa (job #2432333) | Cod sursa (job #2166219)
#include <vector>
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int mod = 666013;
int n, op, nr;
vector <int> h[mod];
bool hfind( int x )
{
int y = x % mod ;
vector <int>::iterator it;
if ( h[y].empty() )
return false;
else
for( it = h[y].begin() ; it != h[y].end() ; ++it )
if( (*it) == x )
return true;
return false;
}
void hpush(int x)
{
int y = x % mod;
if ( !hfind(x))
h[y].push_back(x);
}
void hdelete ( int x)
{
int y = x % mod;
vector <int>::iterator it;
if ( hfind(x) )
{
for(it = h[y].begin() ; (*it) != x ; ++it );
h[y].erase(it);
}
}
int main()
{
f>>n;
int i;
for( i = 0 ; i < n ; i++ )
{
f>>op>>nr;
switch (op)
{
case 1:
hpush(nr);
break;
case 2:
hdelete(nr);
break;
case 3:
g<<hfind(nr)<<"\n";
break;
}
}
}