Cod sursa(job #518596)

Utilizator thesilverhand13FII Florea Toma Eduard thesilverhand13 Data 2 ianuarie 2011 01:11:51
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include<fstream>
#define dim 10001
using namespace std;
int a[dim],n,lung;
ifstream f("perle.in");
ofstream g("perle.out");
int transformaC(int poz);
int transformaB(int poz)
{
	while(poz<=lung&&a[poz]==2)
		poz++;
		if(a[poz]==1&&a[poz+2]==3)
			return transformaC(poz+4);
	else
		return 0;
	
}
int transformaC(int poz)
{
	if(a[poz]==2)
		return poz;
	else
		if(a[poz]==1&&a[poz+1]==2)
			return poz+2;
		else
			if(a[poz]==3)
			{
				int b=transformaB(poz+1);
				if(b!=0)
				 return transformaC(b+1);
				else
					return 0;
			}
			else
				return 0;
}
int verifica()
{
	if(lung==1)
		return 1;
	else
		if(transformaB(1)==lung||transformaC(1)==lung)
			return 1;
	else
		return 0;
}
int main()
{
	int i,j;
	f>>n;
	for(j=1;j<=n;j++)
	{
		f>>lung;
		for(i=1;i<=lung;i++)
		{
			f>>a[i];
			//g<<a[i]<<" ";
		}
		g<<verifica()<<"\n";
		//g<<"\n";
	}
}