这道题目英文叙述了很多,其实就是对于给出的查找字符串,在让改变的字符串中改变部分字符,就是数组字符的前移与后移问题
#include <stdio.h>
#include <string.h>
int main()
{
int i,j,n,m,s,t,x,y,z,k;
char s1[1000][1000];
char s2[1000];
int l1,l2,l;
while(scanf("%d",&n)!=EOF)
{
getchar ();
if(n==0)
{
break;
}
for(i=0;i<=2*n-1;i++)
{
gets(s1[i]);
}
gets(s2);
l2=strlen(s2);
for(i=0;i<=2*n-1;i+=2)
{
l1=strlen(s1[i]);
if(l2>=l1)
{
l=strlen(s1[i+1]);
while(1)
{
l2=strlen(s2);
for(x=0;x<=l2-1;x++)
{
if(s2[x]==s1[i][0])
{
for(y=0;y<=l1-1&&y+x<=l2-1;y++)
{
if(s1[i][y]==s2[y+x])
{
;
}else
{
break;
}
}
if(y==l1)
{
break;
}
}
}
if(x==l2)
{
break;
}else
{
if(l1==l)
{
for(y=0;y<=l1-1;y++)
{
s2[x+y]=s1[i+1][y];
}
}else if(l1>l)
{
for(y=0;y<=l-1;y++)
{
s2[x+y]=s1[i+1][y];
}
k=x+y;
for(x=x+l1;x<=l2;x++)
{
s2[k]=s2[x];
k+=1;
}
}else
{
k=l-l1;
for(z=l2;z>=x+l1;z--)
{
s2[z+k]=s2[z];
}
for(z=0;z<=l-1;z++)
{
s2[x+z]=s1[i+1][z];
}
}
}
}
}
}
puts(s2);
}
return 0;
}