Pagini recente » Cod sursa (job #424461) | Cod sursa (job #2730530) | Cod sursa (job #1641340) | Cod sursa (job #2887939) | Cod sursa (job #2298733)
#include "pch.h"
#include <iostream>
#include <fstream>
const int 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;
}
int main()
{
f >> n;
for (int i = 0; i < n; i++)
{
int m;
f >> m;
for (int j = 0; j < m; j++)
f >> v[j];
if (m == 1 || perlaB(0) == m || perlaC(0) == m)
g << 1 << '\n';
else
g << 0 << '\n';
}
return 0;
}