Cod sursa(job #2557237)

Utilizator vlasdumitruVlas Dumitru vlasdumitru Data 25 februarie 2020 17:41:00
Problema Perle Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.08 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");

int st[10005],q,j,n,dr,i;
int main()
{
    fin>>q;
    for (j=1; j<=q; j++)
    {
        fin>>n;
        dr=n;
        for (i=1; i<=n; i++)
        {
            fin>>st[i];
        }
        for (i=n; i>=1; i--)
        {
            if (st[i]==1)
            {
                if (st[i+1]==2 and st[i+2]==65)
                {
                    dr=i;
                    st[i]=67;
                }
                else
                {
                    if (st[i+1]==65 and st[i+2]==3)
                    {
                        dr=i;
                        st[i]=66;
                    }
                    else
                    {
                        st[i]=65;
                    }
                }
            }
            else
            {
                if (st[i]==2)
                {
                    if (st[i+1]==66)
                    {
                        dr=i;
                        st[i]=66;
                    }
                    else
                    {
                        if (dr==i)
                        {
                            st[i]=67;
                        }
                        else
                        {
                            st[i]=65;
                        }
                    }
                }
                else
                {
                    if (st[i+1]==66 and st[i+2]==67)
                    {
                        dr=i;
                        st[i]=66;
                    }
                }
            }
        }
        if (dr==1)
            fout<<1<<'\n';
        else
            fout<<0<<'\n';
    }
    return 0;
}
/*
if (st[i+1]==0)
            {
                if (st[i]!=2)
                {
                    if (i>2)
                    {
                        if (st[i-2]==1 and st[i-1]==2)
                            st[i]=65;
                    }
                }
            }*/