Cod sursa(job #1623200)

Utilizator darmazDarmaz Andrei Sebastian darmaz Data 1 martie 2016 17:55:38
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
using namespace std;

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

int n,k,v[10009];
int B(int x);
int C(int x);

int B(int x){
    if(v[x]==2) return B(x+1);
    if(v[x]==1 && v[x+2]==3) return C(x+4);
    return 0;
}

int C(int x){
    if(v[x]==2) return x+1;
    if(v[x]==3) return C(B(x+1));
    if(v[x]==1 && v[x+1]==2) return x+3;

}
int main()
{   in>>n;
    for(int i=1;i<=n;i++){
        in>>k;
        for(int j=1;j<=k;j++){
            in>>v[j];
        }
        if(k==1 || B(1)==k+1 || C(1)==k+1) out<<1<<'\n';
         else out<<0<<'\n';
    }
    return 0;
}