I - Shuffle'm Up
src="https://vjudge.net/problem/description/8033?1516092013000" width="100%" height="1981px" frameborder="0" scrolling="no" style="box-sizing: inherit;">
#include<stdio.h>
#include<string.h>
char s1[500], s2[500], s3[1000], s[1000];
int len, n, flag, flag1, sum;
void dfs(int cur)
{
int i, j;
if(cur==100)
{
flag1=1;
return ;
}
if(strncmp(s, s3, 2*len)==0)
{
flag=1;
sum=cur;
return ;
}
if(flag || flag1)
return ;
for(i=0, j=0;i<len;i++)
{
s[j++]=s2[i];
s[j++]=s1[i];
}
strncpy(s1, s, len);
strncpy(s2, s+len, len);
if(strncmp(s, s3, 2*len)==0)
{
flag=1;
sum=cur;
return ;
}
else
dfs(cur+1);
}
int main()
{
int i, j, ca;
scanf("%d", &n);
for(ca=1;ca<=n;ca++)
{
flag=0;flag1=0;
scanf("%d", &len);
scanf("%s%s%s", s1, s2, s3);
dfs(1);
if(!flag)
sum=-1;
printf("%d %d\n", ca, sum);
}
return 0;
}