Pagini recente » Cod sursa (job #402793) | Cod sursa (job #279455) | Cod sursa (job #3159212) | Cod sursa (job #3182398) | Cod sursa (job #2711061)
// perle.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <fstream>
#include <string>
using namespace std;
ifstream in("perle.in");
ofstream out("perle.out");
int poz, n, a[100010], t, i, x;
bool adB();
bool adC() {
if (poz > n)
return 0;
if (a[poz] == 2) {
poz++;
return 1;
}
if (a[poz] == 1 && a[poz + 1] == 2 && poz + 2 <= n) {
poz += 3;
return 1;
}
if (a[poz] == 3)
return adB() && adC();
return 0;
}
bool adB() {
if (poz > n)
return 0;
if (a[poz] == 2) {
poz++;
return adB();
}
if (a[poz] == 1 && a[poz + 2] == 3)
{
poz += 4;
return adC();
}
return 0;
}
int main() {
in >> t;
for (; t; t--) {
in >> n;
for (i = 1; i <= n; i++)
in >> a[i];
poz = 1;
if (n == 1) {
out << "1\n";
continue;
}
if ((n >= 5 && a[1] == 1 && a[3] == 3) || a[1] == 2) {
out << adB() << '\n';
continue;
}
out << adC() << '\n';
}
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file