Cod sursa(job #1395751)

Utilizator DobosDobos Paul Dobos Data 21 martie 2015 14:22:25
Problema Perle Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
int v[1020],n;
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++;
    if(v[x] == 1 && v[x+1] == 2)
     return    x += 3;
       if(v[x] == 3)
        return c(b(x+1));
        return 0;

}

int main()
{
    int nr,i;
    f>>nr;
    for(int j = 1; j <= nr; j++)
    {
        f>>n;
        for(i = 1; i <= n ; i++)
            f>>v[i];
            if(n == 1 || b(1) == n+1 || c(1) == n+1)
            g<<1<<"\n";
            else
            g<<0<<"\n";
    }

    return 0;
}