Pagini recente » Cod sursa (job #745954) | Cod sursa (job #547795) | Cod sursa (job #2445524) | Cod sursa (job #3031288) | Cod sursa (job #2108473)
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int MOD = 666013;
struct elem{
int val;
elem *next;
};
elem *(v[MOD]);
void push(int val){
int hashIndex = val%MOD;
elem *newElem = new elem;
newElem->val = val;
newElem->next = v[hashIndex];
v[hashIndex] = newElem;
}
void pop(int val){
elem *crtElem = v[val%MOD];
if(!crtElem)
return;
else
{
if(!crtElem->next)
{
if(crtElem->val == val)
v[val%MOD] = NULL;
}
else
{
while(crtElem != NULL && crtElem->next != NULL){
if(crtElem->next->val == val)
{
crtElem->next = crtElem->next->next;
return;
}
crtElem = crtElem->next;
}
}
}
}
int checkExistence(int val){
elem *crtElem = v[val%MOD];
while(crtElem != NULL){
if(crtElem->val == val)
return 1;
crtElem = crtElem->next;
}
return 0;
}
int main()
{
int n;
in>>n;
while(n--)
{
int op,x;
in>>op>>x;
if(op == 1)
{
if(!checkExistence(x))
push(x);
}
else if(op == 2)
{
///if(checkExistence(x))
pop(x);
}
else
{
out<<checkExistence(x)<<"\n";
}
}
return 0;
}