Cod sursa(job #2298742)

Utilizator Mihnea_11Mihnea Lopataru Mihnea_11 Data 8 decembrie 2018 13:58:38
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
//#include "pch.h"
#include <iostream>
#include <fstream>

#define nmax 10025

using namespace std;

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

int n, v[nmax];

int perlaB(int pozitie);
int perlaC(int pozitie);

int perlaB(int pozitie)
{
	if (v[pozitie] == 2)
		return perlaB(pozitie + 1);

	if (v[pozitie] == 1 && v[pozitie + 2] == 3)
		return perlaC(pozitie + 4);

	return 0;
}

int perlaC(int pozitie)
{
	if (v[pozitie] == 2)
		return pozitie + 1;

	if (v[pozitie] == 3)
		return perlaC(perlaB(pozitie + 1));

	if (v[pozitie] == 1 && v[pozitie + 1] == 2)
		return pozitie + 3;

	return 0;
}

int main()
{
	if (f.is_open())
	{
		f >> n;
		for (int i = 0; i < n; i++)
		{
			int m;
			f >> m;
			for (int j = 1; j <= m; j++)
				f >> v[j];

			if (m == 1 || perlaB(1) == m + 1 || perlaC(1) == m + 1)
				g << 1 << '\n';
			else
				g << 0 << '\n';
		}
	}
	else
		cout << "ERROR OCCURED";
	f.close();
	g.close();
	return 0;
}