Cod sursa(job #2916786)

Utilizator Victor280605Victor Dragos Victor280605 Data 1 august 2022 15:23:24
Problema Perle Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <iostream>
#include <fstream>
using namespace std;

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


short v[10010]={0};
short lung;
bool testc(int i);
bool testa(int i){
    if(v[i]==1 || v[i]==2 || v[i]==3){
        return 1;
    }
    else{
        return 0;
    }
}

bool testb(int i){
    // sa nu uiti sa pui cv regula ca asta poate merge la infinit
    if(v[i]==2 && testb(i+1)==1){
       return 1;
    }
    else if(v[i]==1 && testa(i+1)==1 && v[i+2]==3 && testa(i+3)==1 && testc(i+4)==1){
        return 1;
    }
    else{
        return 0;
    }
}

bool testc(int i){

    if(v[i]==2 && v[i+1]==0){
        return 1;
    }
    else if(v[i]==3 && testb(i+1)==1 && testc(i+2)==1){
        return 1;
    }
    else if(v[i]==1 && v[i+1]==2 && testa(i+2)==1 && v[i+3]==0){
        return 1;
    }
    else{
        return 0;
    }
}


bool testare(int i){
    //mai vezi la primu test asta cu a ca poate nu e bine
 if(testa(i)==1 && v[i+1]==0 || testb(i)==1 || testc(i)==1){
    return 1;
 }
 else{
    return 0;
 }

}



int main()
{

   int n,i,j;
   in >> n;
   for(i=1;i<=n;i++){
    in >> lung;
    for(j=1;j<=lung;j++){
        in >> v[j];
    }
    out << testare(1) << endl;

    for(j=1;j<=lung;j++){
        v[j]=0;
    }
   }
}