Pagini recente » Cod sursa (job #1987007) | Cod sursa (job #2590399)
#include <fstream>
#include <ios>
#include <cstring>
#include <string>
using US = unsigned short;
US N, len_arr;
US arr[10010];
US pos;
void C();
void B()
{
if (pos >= len_arr || arr[pos] == 3)
{
return;
}
if (arr[pos] == 1 && arr[pos + 2] == 3)
{
pos += 4;
C();
}
else if (arr[pos] == 2)
{
++pos;
B();
}
}
void C()
{
if (pos >= len_arr)
{
return;
}
if (arr[pos] == 1)
{
pos += 2;
return;
}
if (arr[pos] == 2)
{
++pos;
return;
}
++pos;
B();
++pos;
C();
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::ifstream fisierIN("perle.in");
std::ofstream fisierOUT("perle.out");
fisierIN.tie(NULL);
fisierOUT.tie(NULL);
fisierIN >> N;
for (US i = 0; i < N; ++i)
{
fisierIN >> len_arr;
for (US j = 0; j < len_arr; ++j)
{
fisierIN >> arr[j];
}
if (len_arr == 1 || len_arr == 3)
{
fisierOUT << "1\n";
continue;
}
if (arr[0] == 1 || arr[0] == 2)
{
++pos;
B();
}
else
{
++pos;
C();
}
fisierOUT << (pos == len_arr - 1) << "\n";
pos = 0;
memset(arr, 0, sizeof arr);
}
}