Pagini recente » Monitorul de evaluare | Cercetași | Istoria paginii utilizator/plosceanu_dennis_323ca | Istoria paginii runda/utcn-2021-practice/clasament | Cod sursa (job #312096)
Cod sursa(job #312096)
#include <stdio.h>
#define MaxL 9
int n, length, v[MaxL];
int a(int poz);
int b(int poz, int FromC);
int c(int poz);
int a(int poz){
if ( poz <= length ) return 1;
return 0;
}
int b(int poz, int FromC){
bool val = false;
if (FromC == 0){
switch ( v[poz] ) {
case 2 : if ( (poz <= (length - 1) ) && ( b(poz + 1, 0) ) ) val = true;
case 1 : if ( ( poz <= length - 4) && (( v[poz + 2] == 3 ) && ( a(poz + 1) ) && ( a (poz + 3) ) && ( c(poz + 4) ) ) ) val = true;
};
}
if (FromC) {
switch ( v[poz] ) {
case 2 : if ( (poz <= (length - 1) ) && ( b(poz + 1, 1) ) ) val = true;
case 1 : if ( ( poz <= length - 4) && (( v[poz + 2] == 3 ) && ( a(poz + 1) ) && ( a (poz + 3) ) && ( c(poz + 4) ) && ( c(poz + 5) ) ) ) val = true;
};
}
if (val) return 1;
return 0;
};
int c(int poz){
bool val = false;
if ( (poz == length) && (v[poz] == 2) ) val = true;
if ( (poz == length - 2) && ( (v[poz] == 1) && (v[poz+1] == 2) ) ) val = true;
if ( (poz < length - 7) && (v[poz] == 3 && b(poz + 1, 1) ) ) val = true;
if (val) return 1;
return 0;
}
int test (){
if ( a(1) && length == 1) return 1;
if ( b(1,0) ) return 1;
if ( c(1) ) return 1;
return 0;
}
int main(){
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++){
for (int j = 1; j <= 10; j++)
v[ j ] = 0;
scanf("%d", &length);
for (int j = 1; j <= length; j++)
scanf("%d", &v[ j ]);
if ( test() )
printf("1\n");
else
printf("0\n");
};
return 0;
}