Pagini recente » Cod sursa (job #2447532) | Cod sursa (job #1753100)
#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;
}