Cod sursa(job #1753100)

Utilizator ade_tomiEnache Adelina ade_tomi Data 5 septembrie 2016 20:31:03
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <iostream>
#include <fstream>
#define NMAX 100003
using namespace std;
int a[NMAX], n, ok, p;

int expandC (int poz);

int expandB (int poz)
{
    //cout << " expandB " << poz << "\n";
    if (a[poz] == 2)
        return expandB (poz + 1);
    if (a[poz] == 1 && a[poz + 2] == 3)
        return expandC (poz + 4);
    cout<<poz;
    return -1;

}

int expandC (int poz)
{
//    cout << "expandc" << poz << "\n";
    if (a[poz] == 2)
        return poz + 1;
    if (a[poz] == 1 && a[poz + 1] == 2)
        return poz + 3;
    if (a[poz] == 3)
        return expandC (expandB (poz + 1));
    //cout<<poz;
    return -1;
}
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];
        ok = expandB (1);
     //  cout << ok << "\n";
       
       if (ok != n + 1)
            ok = expandC (1);
        if (n == 1)
            ok = 2;
       if (ok == n + 1)
           cout << "1\n";
       else 
       cout << 0  << "\n";
        T--;
        ok = 0;
    }
    return 0;
}