Cod sursa(job #1224701)

Utilizator TimitocArdelean Andrei Timotei Timitoc Data 31 august 2014 17:07:13
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXL 10015

using namespace std;

int a[MAXL];
int n, len;
void sol();
void citire()
{
    scanf("%d ", &n);
    for (int i = 0; i < n; i++)
    {
       scanf("%d", &len);
       for (int j = 0; j < len; j++)
           scanf("%d", &a[j]);
        sol();
    }
}
int C(int);
int B(int pos)
{
    if (pos > len)
        return 0;
    if (a[pos] == 2)
        return B(pos+1);
    if (a[pos] == 1 && a[pos+2] == 3)
        return C(pos+4);
    return 0;
}

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

void sol()
{
    if (len == 1 || B(0) == len || C(0) == len)
        printf("1\n");
    else
        printf("0\n");
}

int main()
{
    freopen("perle.in", "r", stdin);
    freopen("perle.out", "w", stdout);

    citire();

    return 0;
}