Pagini recente » Cod sursa (job #1901301) | Cod sursa (job #477126) | Cod sursa (job #2382299) | Cod sursa (job #2700283) | Cod sursa (job #2731216)
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
using namespace std;
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
int main()
{
int N,i,op,nr;
const int prime=655357;
int hashnr;
bool ok;
vector <list<unsigned>> hashuri(hashnr);
f>>N;
for (i=0; i<N; i++)
{
f>>op>>nr;
hashnr=nr%prime;
if (op==1)
{
ok=true;
for (std::list<unsigned>::iterator it=hashuri[hashnr].begin(); it!=hashuri[hashnr].end(); ++it)
if (*it==nr)
{
ok=false;
break;
}
if (ok)
hashuri[hashnr].push_back(nr);
}
else if (op==2)
{
for (std::list<unsigned>::iterator it=hashuri[hashnr].begin(); it!=hashuri[hashnr].end(); ++it)
if (*it==nr)
{
hashuri[hashnr].erase(it);
break;
}
}
else
{
ok=false;
for (std::list<unsigned>::iterator it=hashuri[hashnr].begin(); it!=hashuri[hashnr].end(); ++it)
if (*it==nr)
{
g<<1<<"\n";
ok=true;
break;
}
if (!ok)
g<<0<<"\n";
}
}
}