Pagini recente » Cod sursa (job #2815498) | Cod sursa (job #1442903) | Cod sursa (job #2900762) | Cod sursa (job #2311763) | Cod sursa (job #2927822)
#include<fstream>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<cstring>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
//ifstream f("in.in");
//ofstream g("out.out");
bool a();
bool b();
bool c();
int n,m;
int poz=0;
int v[10005];
bool a(){
//cout<<"A: "<<poz<<'\n';
if(poz > m){
return 0;
}
if(v[poz] == 1 || v[poz] == 2 || v[poz] == 3){
poz++;
return 1;
}
return 0;
}
bool b(){
//cout<<"B: "<<poz<<'\n';
if(poz > m){
return 0;
}
if(v[poz] == 1){
/// 1
poz++;
/// a
if(a() == 0){
return 0;
}
/// 3
if(v[poz] != 3 || poz > m){
return 0;
}
poz++;
/// a
if(a() == 0){
return 0;
}
/// c
if(c() == 0){
return 0;
}
return 1;
}
if(v[poz] == 2){
/// 2;
poz++;
/// b
if(b() == 0){
return 0;
}
return 1;
}
return 0;
}
bool c(){
//cout<<"C: "<<poz<<'\n';
if(poz > m){
return 0;
}
if(v[poz] == 1){
/// 1
poz++;
/// 2
if(v[poz] != 2 || poz > m){
return 0;
}
poz++;
/// a
if(a() == 0){
return 0;
}
return 1;
}
if(v[poz] == 2){
///2
poz++;
return 1;
}
if(v[poz] == 3){
/// 3
poz++;
/// b
if(b() == 0){
return 0;
}
/// c
if(c() == 0){
return 0;
}
return 1;
}
return 0;
}
int main(){
f>>n;
for(int i=1;i<=n;i++){
f>>m;
for(int j=1;j<=m;j++){
f>>v[j];
}
poz=1;
if(a() == 1 && poz == m+1){
//g<<"POZ = "<<poz<<'\n';
g<<1<<'\n';
continue;
}
//cout<<'\n';
//g<<"POZ = "<<poz<<'\n';
poz=1;
if(b() == 1 && poz == m+1){
//g<<"POZ = "<<poz<<'\n';
g<<1<<'\n';
continue;
}
//cout<<'\n';
//g<<"POZ = "<<poz<<'\n';
poz=1;
if(c() == 1 && poz == m+1){
//g<<"POZ = "<<poz<<'\n';
g<<1<<'\n';
continue;
}
//cout<<'\n';
//g<<"POZ = "<<poz<<'\n';
//cout<<">---------------------------<"<<'\n'<<'\n';
g<<0<<'\n';
}
f.close();
g.close();
return 0;
}