Cod sursa(job #1753065)

Utilizator ade_tomiEnache Adelina ade_tomi Data 5 septembrie 2016 19:30:37
Problema Perle Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <iostream>
#include <fstream>
#define NMAX 10003
using namespace std;
int a[NMAX], n, ok;
void  expand (int poz, char c)
{

    //cout << poz << " " << c << "\n";
    if (c == 'B')
    {
  //      cout << "HERE" << poz << "\n";
        if (a[poz] == 2 && poz + 1 <= n)
            expand (poz + 1, 'B');
        if (poz + 4 <= n && a[poz] == 1 && a[poz + 2] == 3)
             expand (poz + 4, 'C');
    }
    if (c == 'C')
    {
//        cout << "here?";
        if (a[poz] == 2 && poz == n)
            ok = 1;
        if (a[poz] == 1 && a[poz + 1] == 2 && poz + 2 == n)
            ok = 1;
        if (a[poz] == 3 && poz + 2 <= n)
             expand (poz + 2, 'C');
       // return 0;

    }
   // cout << "\n\n";
}
int main()
{
    int T;
    ifstream cin ("perle.in");
    ofstream cout ("perle.out");
    cin >> T;
    while (T)
    {
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        expand (1, 'B');
        if (!ok)
            expand (1, 'C');
        if (n == 1)
            ok = 1;
        cout << ok << "\n";
        T--;
        ok = 0;
    }
    return 0;
}