Cod sursa(job #1472005)

Utilizator mateidanutDanut Gabriel Matei mateidanut Data 15 august 2015 21:01:18
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <fstream>
using namespace std;

struct nod
{	int info;
	nod *urm;
} *v[1000003], *p;

int mod=1000003, op, x, n;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

int main()
{	f>>n;
	for (; n; --n)
	{	f>>op>>x;
		int y, ok=0;
		y=x%mod;
		if (op==1)
		{	for (p=v[y]; p; p=p->urm)
				if (x==p->info)
					ok=1;
			if (!ok)
			{	p=new nod;
				p->info=x;
				p->urm=v[y];
				v[y]=p;
			}
		}
		else
		{	if (op==2)
			{	if (v[y])
				{	if (v[y]->info==x)
					{	p=v[y];
						v[y]=v[y]->urm;
						delete p;
					}
					else
						for (p=v[y]; p->urm; p=p->urm)
							if (p->urm->info==x)
							{	nod *q=p->urm;
								p->urm=q->urm;
								delete q;
								break;
							}
				}
			}
			else
			{	for (p=v[y]; p; p=p->urm)
					if (p->info==x)
						ok=1;
				g<<ok<<'\n';
			}
		}
	}
    return 0;
}