Pagini recente » Cod sursa (job #3162209) | Cod sursa (job #2378933) | Cod sursa (job #3137748) | Cod sursa (job #2176447) | Cod sursa (job #222670)
Cod sursa(job #222670)
#include<stdio.h>
#define M 10003
FILE *f=fopen("perle.in","r");
FILE *g=fopen("perle.out","w");
char st[M];
int y[M],n,l,vf=0,OK=1;
void citire()
{int i,j;
OK=1;
fscanf(f,"%d",&l);
for(j=1;j<=l;j++)
fscanf(f,"%d",&y[j]);
if(l==1) {fprintf(g,"1\n");
OK=0;}
else if(l==2) {fprintf(g,"0\n");
OK=0;}
else if(y[1]==2) {st[1]='2';
st[2]='B';
vf=2;}
else if(y[1]==3) {st[1]='3';
st[2]='B';
st[3]='C';
vf=3;}
else if(y[1]==1&&y[3]==3) {st[1]='1';
st[2]='A';
st[3]='3';
st[4]='A';
st[5]='C';
vf=5;}
else if(y[1]==1&&y[2]==2) {st[1]='1';
st[2]='2';
st[3]='C';
vf=3;}
}
int sir()
{int i;
for(i=1;i<=vf;i++)
if(st[i]=='B') {if(y[i]==1) {st[i]='1';
st[i+1]='A';
st[i+2]='3';
st[i+3]='A';
st[i+4]='C';
vf=vf+4;}
else if(y[i]==2) {st[i]='2';
st[i+1]='B';
vf++;}}
else if(st[i]=='C') {if(y[i]==3) {st[i]='3';
st[i+1]='B';
st[i+2]='C';
vf=vf+2;}
else if(y[i]==1) {st[i]='1';
st[i+1]='2';
st[i+2]='A';
vf=vf+2;}
else if(y[i]==2) st[i]='2';
}
return 0;
}
void verifica()
{int x,i,ok;
if(vf!=l) fprintf(g,"0\n");
else {ok=1;
for(i=1;i<=l&&ok;i++)
if((st[i]=='B')||(st[i]=='C')) ok=0;
else if(st[i]!='A') {x=st[i]-'0';
if(x!=y[i]) ok=0;}
if(ok) fprintf(g,"1\n");
else fprintf(g,"0\n");
}
}
int main()
{int i;
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
{citire();
if(OK==1) {sir();
verifica();}
vf=0;}
fclose(f);
fclose(g);
return 0;
}