http://poj.org/problem?id=3087说好的搜索呢??明明就是个简单的模拟嘛,不过那个字符串处理我还真是有问题啊!!!!!
#include<stdio.h>
#include<string.h>
#include<math.h>
char s1[103],s2[103],s[205],ss[205],s0[205],p[205];
int c,ans;
int shuffle()
{
int i;
strcpy(p,ss);
for (i=0;i<c ;i++ )
{
ss[2*i+1]=p[i];
ss[2*i]=p[c+i];
}
ans++;
}
int main()
{
int t,i,j;
scanf("%d",&t);
for (i=1;i<=t ;i++ )
{
scanf("%d",&c);
scanf("%s%s%s",&s1,&s2,&s);
ans=0;
for (j=0;j<c ;j++ )
{
ss[j]=s1[j];
ss[c+j]=s2[j];
}
ss[2*c]=0;
shuffle();
strcpy(s0,ss);
if (strcmp(s,ss)==0)
{
printf("%d %d\n",i,ans);
}
else
{
while (1)
{
shuffle();
if (strcmp(ss,s0)==0)
{
ans=-1;
break;
}
if (strcmp(ss,s)==0)
break;
}
printf("%d %d\n",i,ans);
}
}
}
字符串处理,字符串!!!