Cod sursa(job #249147)

Utilizator mihnea_andreiMihnea Andrei mihnea_andrei Data 27 ianuarie 2009 18:05:57
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include<fstream> 
#define r 665124
using namespace std; 

struct nod 
{ 
	int info; 
	nod *adr; 
}; 
nod *v[r]; 
ifstream in("hashuri.in"); 
ofstream out("hashuri.out"); 

void adaug (nod *&p,int x) 
{ 
	nod *q=new nod; 
	q->info=x; 
	q->adr=p; 
	p=q;
} 

void sterge (nod *&p, int x) 
{
	if(p==NULL)
		return;
	nod *aux=new nod;
	if(p->info==x) 
	{ 
		aux=p; 
		p=p->adr; 
		delete aux; 
		return; 
	} 
	for (nod* q=p;q->adr;q=q->adr) 
	{ 
		if(q->adr->info==x) 
		{ 
			aux=p->adr; 
			p->adr=aux->adr; 
			delete aux;
			return;
		}
	}
}

void raspuns (nod *&p, int x) 
{ 
	int contor=0; 
	while (p!=NULL) 
	{ 
		if(p->info==x) 
			contor=1;
		p=p->adr;
	}
	if(contor==1) 
		out<<1; 
	else out<<0;
	out<<"\n";	
}
int main () 
{
	long int n,a,b; 
	in>>n;
	while (n--) 
	{ 
		in>>a; 
		in>>b; 
		if(a==1)
			adaug(v[b%r],b);
		if(a==2)
			sterge(v[b%r],b); 
		if(a==3) 
			raspuns(v[b%r],b); 
	} 
	in.close (); 
	out.close (); 
	return 0; 
}