Cod sursa(job #2928139)

Utilizator dragos1102Dragos Vieru dragos1102 Data 22 octombrie 2022 11:34:55
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>
using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");
int n,i,s[10005],l;
int C(int x);
int B(int x) {
if(s[x] == 1 && s[x+2] == 3)
    return C(x + 4);
else
    if(s[x] == 2)
        return B(x + 1);
    return 0;
}
int C(int x) {
if(s[x] == 2)
    return x+1;
else
    if(s[x] == 3)
        return C(B(x + 1));
    else
        if(s[x] == 1 && s[x+1] == 2)
            return x+3;
    return 0;
}
int main() {
fin>>n;
for(int nr = 1; nr<=n; nr++) {
    fin >> l;
    for(i=1; i<=l; i++)
        fin>>s[i];
    if(l==1 || B(1)==l+1 || C(1)==l+1)
        fout<<1 <<'\n';
    else
        fout<<0 <<'\n';
}
return 0;
}