Cod sursa(job #2362044)

Utilizator MoodyFaresFares Mohamad MoodyFares Data 2 martie 2019 21:36:39
Problema Perle Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <cstdio>

const int MAX_L = 10000;

int s[MAX_L];

int c(int pos);

int a(int pos) {
  return pos + 1;
}

int b(int pos) {
  if (s[pos] == 1 && s[pos + 2] == 3)
    return c(pos + 4);
  else if (s[pos] == 2)
    return b(pos + 1);
}

int c(int pos) {
  if (s[pos] == 2)
    return pos + 1;
  else if (s[pos] == 3)
    return c(b(pos + 1));
  else if (s[pos] == 1 && s[pos + 1] == 2)
    return a(pos + 2);
}

int main() {
  freopen("perle.in", "r", stdin);
  freopen("perle.out", "w", stdout);

  int t;
  scanf("%d", &t);
  for (int test = 0; test < t; test++) {
    int l;
    scanf("%d", &l);
    for (int i = 0; i < l; i++)
      scanf("%d", &s[i]);
    if (a(0) == l || b(0) == l || c(0) == l)
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}