Cod sursa(job #3198040)

Utilizator radu._.21Radu Pelea radu._.21 Data 28 ianuarie 2024 11:22:08
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.72 kb
#include <fstream>
using namespace std;
int v[10010];
int n, t, i, A(), B(), C(), T;
int A() {
    if (i==n+1)
        return 0;
    if (v[i] == 1 || v[i] == 2 || v[i] == 3) {
        i++;
    return 1;
    }
    else

    return 0;
}
ifstream fin ("perle.in");
ofstream fout("perle.out");
int B() {
    if (i==n+1)
        return 0;
    if (v[i] == 2) {
        i++;
    return B();
    }
    else
        if (v[i] == 1) {
            i++;
            int aux = A();
            if (aux == 0)
            return 0;
        if (v[i] != 3)
            return 0;
        i++;
        aux = A();
        if (aux == 0)
            return 0;
        return C();
    }
        else
            return 0;
}
int C(){ /// da rezultat 1 daca C poate genera restul de
    /// sir incepand cu valoarea curenta a lui i
    if (i==n+1)
        return 0;
    if (v[i] == 2) {
        i++;
    return 1;
    } else
    if (v[i] == 1) {
        i++;
    if (v[i] != 2) {
        i++;
    return 0;
    } else {
        i++;
    return A();
    }
    } else {
        i++;
        int aux = B();
        if (aux == 0)
            return 0;
    return C();
    }
}
int main (){

    for (fin>>T; T--; ) {
        fin>>n;
        for (i=1;i<=n;i++)
            fin>>v[i];
        i = 1;
        int rez = A();
        if (rez == 1 && i == n+1) {
            fout<<"1\n";
        continue;
        }
        i = 1;
        rez = B();
        if (rez == 1 && i == n+1) {
            fout<<"1\n";
            continue;
        }
        i = 1;
        rez = C();
        if (rez == 1 && i == n+1) {
            fout<<"1\n";
        continue;
        }
        fout<<"0\n";
    }
    return 0;
}