Cod sursa(job #932728)

Utilizator PetrutiuPaulPetrutiu Paul Gabriel PetrutiuPaul Data 29 martie 2013 10:31:11
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <stdio.h>

using namespace std;

int N,v[10001],i,p;

int B(int x);
int C(int x);

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

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

}

int main()
{
    ifstream fin("perle.in");
    ofstream fout("perle.out");
    fin>>N;
    for (p=1;p<=N;p++) {
        fin>>v[0];
        for (i=1;i<=v[0];i++)
            fin>>v[i];
        if (v[0]==1 || B(1)==v[0]+1 || C(1)==v[0]+1)
            fout<<1<<'\n';
        else fout<<0<<'\n';
    }
    return 0;
}