Pagini recente » Cod sursa (job #919560) | Cod sursa (job #533935) | Cod sursa (job #33552) | Cod sursa (job #2123600) | Cod sursa (job #31938)
Cod sursa(job #31938)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char a[10001],b[10001],temp[10001];
unsigned int i,j,n,l,ok,c,i1;
int main()
{ FILE *f,*g;
f=fopen("perle.in","r");
g=fopen("perle.out","w");
fscanf(f,"%d",&n);
for(i1=1;i1<=n;i1++)
{ fscanf(f,"%d",&l);
for(j=0;j<l;j++)
{fscanf(f,"%d",&c);b[j]='1'+c-1;}
if(strlen(b)==1)a[0]='a';
else if(b[0]=='2')a[0]='b';
else if(b[0]=='3')a[0]='c';
else if(strlen(b)<5)a[0]='c';
else a[0]='b';
ok=1;
while(ok==1)
{ if((strlen(a)*strlen(b))==0)ok=2;
if(strlen(b)<strlen(a))ok=0;
if(ok==1)
{ if((a[0]==b[0])||(a[0]=='a'))
{for(i=0;i<=strlen(a);i++)a[i]=a[i+1];
for(i=0;i<=strlen(b);i++)b[i]=b[i+1];}
else if((a[0]=='b')&&(b[0]=='2'))for(i=0;i<=strlen(b);i++)b[i]=b[i+1];
else if((a[0]=='b')&&(b[0]=='1'))
{for(i=0;i<=strlen(a);i++)a[i]=a[i+1];strcpy(temp,"");
strcat(temp,"1a3ac");strcat(temp,a);strcpy(a,temp);}
else if((a[0]=='c')&&(b[0]=='3'))
{strcpy(temp,"");strcat(temp,"3b");strcat(temp,a);strcpy(a,temp);}
else if((a[0]=='c')&&(b[0]=='1'))
{for(i=0;i<=strlen(a);i++)a[i]=a[i+1];strcpy(temp,"");
strcat(temp,"12a");strcat(temp,a);strcpy(a,temp);}
else ok=0;
}
}
if(ok==2) fprintf(g,"1\n");
else fprintf(g,"0\n");strcpy(a,"");strcpy(b,"");
}
fprintf(g,"\n");
fcloseall();
return 0;
}