Cod sursa(job #2157389)

Utilizator bogdanbenteaBentea Bogdan bogdanbentea Data 9 martie 2018 16:38:09
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.89 kb
#include <fstream>
using namespace std;
ifstream cin("perle.in");
ofstream cout("perle.out");

int l,i,j,n,v[10002];

void c(int &x);
void b(int &x);

void b(int &x)
{
    if(x<l)
    {
        if(v[x]==2)
        {
            ///verif daca v[x+1] e b
            x++;
            b(x);
        }
        else
        {
            if(v[x]==1)
            {
                ///verif daca v[x+2] e 3
                ///verif daca v[x+4] e c
                if(v[x+2]==3 && x+4<=l)
                {
                    x+=4;
                    c(x);
                }
            }
        }
    }
}

void c(int &x)
{
    if(x<=l)
    {
        if(v[x]==2)
            x++;
        else
        {
            if(v[x]==3 && x+2<=l)
            {
                ///verif daca v[x+1] e b
                ///verif daca v[x+2] e c
                x++;
                b(x);
                x=x;
                c(x);
            }
            else
            {
                if(v[x]==1)
                {
                    ///verif daca v[x+1] e 2
                    ///true
                    if(v[x+1]==2 && x+3<=l+1)
                    {
                        x+=3;
                    }
                }
            }
        }
    }
}

int main()
{
    int x;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>l;
        for(j=1;j<=l;j++)
            cin>>v[j];
        if(l==1)
        {
            cout<<1<<'\n';
        }
        else
        {
            x=1;
            b(x);
            if(x==l+1)
                cout<<1<<'\n';
            else
            {
                x=1;
                c(x);
                if(x==l+1)
                    cout<<1<<'\n';
                else
                    cout<<0<<'\n';
            }
        }
    }

    cin.close();
    cout.close();
    return 0;
}