Cod sursa(job #2778750)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 2 octombrie 2021 09:18:34
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
int n,i,s[10010];
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()
{
    f>>n;
    while(n--) {
        f>>s[0];
        for(i=1;i<=s[0];++i)
            f>>s[i];
        if(s[0]==1||B(1)==s[0]+1||C(1)==s[0]+1)
            g<<"1\n";
        else
            g<<"0\n";
    }
    return 0;
}