Pagini recente » Cod sursa (job #702872) | Cod sursa (job #549060) | Cod sursa (job #2789809) | Cod sursa (job #876326) | Cod sursa (job #1017993)
//
// main.cpp
// hasuri
//
// Created by Catalina Brinza on 10/26/13.
// Copyright (c) 2013 Catalina Brinza. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct nod
{
int v;
nod *next;
};
nod *a[3001]; int p=3001;
void h1(int x)
{nod *m=new nod;
if (a[x%p]->v==0)
{
a[x]->v=x;
a[x]->next=NULL;
}
else
{
m=a[x%p];
while (m->next->v<x) m=m->next;
if (m->next->v!=x)
{
nod *q=new nod;
q->next=m->next;
m->next=q;
q->v=x;
}
}
return;
}
void h2(int x)
{
nod *q=new nod;
nod *m=new nod;
m=a[x%p];
q=m->next;
while (m->next!=NULL)
if (q->v==x) {
m=q->next;
delete q;
return;
}
else {m=q; q=q->next;}
return;
}
void h3(int x)
{
nod *m=new nod;
m=a[x%p];
while (m->next!=NULL)
if (m->v==x){ g<<1<<"\n";return;}
else m=m->next;
g<<0<<"\n";return;
}
void dele(nod *p)
{
if (p->next!=NULL)
dele(p->next);
delete p;
}
int main()
{int i,n,x,y;
f>>n;
for (i=0;i<p;i++)
for (i=0;i<n;i++)
{
f>>y>>x;
if (y==1) h1(x);
else if (y==2) h2(x);
else h3(x);
}
f.close();
g.close();
for (i=0;i<3001;i++) dele(a[i]);
return 0;
}