Pagini recente » Rating Vlad Matei Draghici (draghici.vlad18) | Rating Mara Valean (MaraValean) | Statistici Stelian (stecy) | Statistici Claudiu Coman (klauskoman) | Cod sursa (job #857597)
Cod sursa(job #857597)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
int v[10002];
int rezB(int poz);
int rezC(int poz)
{
if (v[poz]==2)
{
if (poz==v[0]) return 1;
return rezC(poz+1);
}
if (v[poz]==1 && v[poz+1]==2)
{
if (poz+2==v[0]) return 1;
return rezC(poz+3);
}
if (v[poz]==3) return rezB(poz+1);
return 0;
}
int rezB(int poz)
{
if (v[poz]==2) return rezB(poz+1);
if (v[poz]==1 && v[poz+2]==3) return rezC(poz+4);
return rezC(poz+1);
}
int rezolva()
{
if (v[0]==1) return 1;
else if (v[0]==2) return 2;
if (v[1]==3) return rezC(1);
return rezB(1);
}
int main()
{
int n, i, j; f>>n;
for (i=0; i<n; i++){f>>v[0];for (j=1; j<=v[0]; j++) f>>v[j];g<<rezolva()<<endl;}
return 0;
}