Cod sursa(job #1181895)

Utilizator apopeid15Apopei Daniel apopeid15 Data 4 mai 2014 10:29:06
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<fstream>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
int a[10001],i,k,nr,j;
int B(int x);
int C(int x);
int B(int x)
{
    if(a[x]==2)
      return B(x+1);
    if(a[x]==1&&a[x+2]==3)
      return C(x+4);
      return 0;
}
int C(int x)
{
    if(a[x]==2)
      return x+1;
    if(a[x]==3)
      return C(B(x+1));
    if(a[x]==1&&a[x+1]==2)
      return x+3;
}
int main()
{
    f>>nr;
    for(j=1;j<=nr;j++)
    {
        f>>k;
        for(i=1;i<=k;i++)
        f>>a[i];
        if(k==1||B(1)==k+1||C(1)==k+1)
        g<<1<<"\n";
        else
        g<<0<<"\n";
    }
    return 0;
}