Pagini recente » Cod sursa (job #2667849) | Cod sursa (job #1985946) | Cod sursa (job #2499784) | Cod sursa (job #1565669) | Cod sursa (job #1041878)
#include <iostream>
//#include <unordered_map>
#include <algorithm>
#include <fstream>
std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");
struct nod
{
int val;
nod *next;
};
int n;
//std::unordered_map<int, bool> hashu;
void citire()
{
nod *prim = new nod;
nod *ultim = prim;
prim->next = NULL;
int x, y;
fin>>n;
for(int i = 0; i < n; i++)
{
fin>>x>>y;
if(x == 1)
{
//hashu[y] = 1;
nod *val = prim;
bool found = false;
while(val)
{
// std::cout<<val->val<<'\n';
if(val->val == y)
{
found = true;
break;
}
val = val->next;
}
if(!found)
{
nod *newNod = new nod;
newNod->val = y;
newNod->next = NULL;
ultim->next = newNod;
ultim = newNod;
}
}
else
if(x == 2)
{
// std::cout<<"here2"<<'\n';
nod *val = prim->next;
nod *lastVal = prim;
while(val)
{
if(val->val == y)
{
lastVal->next = val->next;
delete val;
break;
}
val = val->next;
lastVal = lastVal->next;
}
// hashu.erase(y);
}
else
{
// std::cout<<"here3"<<'\n';
nod *val = prim->next;
bool found = false;
while(val)
{
if(val->val == y)
{
fout<<1<<'\n';
found = true;
break;
}
val = val->next;
}
if(!found)
{
fout<<0<<'\n';
}
// fout<<hashu[y]<<'\n';
}
}
}
int main()
{
citire();
return 0;
}