Cod sursa(job #2298464)

Utilizator vladistr08Vlad Istratescu vladistr08 Data 8 decembrie 2018 10:44:33
Problema Perle Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("perle.in");
ofstream fout("perle.out");

int n, a[10002], k, j;

void citire(){
    fin >> k;
    for(int i = 1; i <=k; i++){
        fin >> a[i];
    }
}
int A(int i)
{
    j=i;
    if(i==k)
        return 1;
    return 0;
}
int B(int i);
int C(int i)
{
    if(a[i]==2)
    {
        j=i;
        if(i==k)
            return 1;
    }    
    if(a[i]==1)
        return A(i+2);
    if(a[i]==3)
    {
        B(i+1);
        return C(j+1);
    }    
    return 0;
}
int B(int i)
{
    if(a[i]==2)
        return B(i+1);
    else
        return C(i+4);
}
bool perle(){
    if(k == 1)
        return 1;
    if(a[1]==1 || a[1]==2)
        if(B(1)==1)
            return 1;
    if(C(1)==1)
        return 1;
    return 0;
}

int main()
{
    fin >> n;
    for(int i = 0; i < n; i++)
    {
        citire();
        fout << perle() << '\n';
    }
    return 0;
}