Cod sursa(job #1908231)

Utilizator BondyBondoc Alexandru Ionut Bondy Data 6 martie 2017 23:45:57
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>

using namespace std;

ifstream f ("perle.in");
ofstream g ("perle.out");

int perle[10001], n;

int caseB( int p );
int caseC( int p );

int main()
{
    f >> n;
    for( int i = 1 ; i <= n ; i ++ ){
        int j = 0;
        do{
            f >> perle[ j ];
            j ++;
        }while( j <= perle[ 0 ] );
        if( perle[ 0 ] == 1 || caseB( 1 ) == j || caseC( 1 ) == j ) g << 1 << endl;
        else g << 0 << endl;
    }
    return 0;
}

int caseB( int p ){
    if( perle[ p ] == 2 ) return caseB( p + 1 );
    if( perle[ p ] == 1 && perle[ p + 2 ] == 3 ) return caseC( p + 4 );
    return 0;
}

int caseC( int p ){
    if( perle[ p ] == 3 ) return caseC( caseB( p + 1 ) );
    if( perle[ p ] == 1 && perle[ p + 1 ] == 2 ) return p + 3;
    if( perle[ p ] == 2 ) return p + 1;
    return 0;
}