删除字符串中的子串
2012-06-14 15:28
232 查看
利用串的基本运算,编写一个算法删除串s1中所有的s2子串
void index(strtype *s1,strtype *s2);
void search(strtype *s1,strtype *s2,int i)
{
if(i>=len(s1))
return ;
else
{
int k=i,j=0;
int m=k;
while(s1->ch[k]==s2->ch[j] && j<=len(s2))
{
k++;
j++;
}
if(j>=len(s2))
{
index(del(s1,m+1,len(s2)),s2);
}
else
search(s1,s2,i+1);
}
}
void index(strtype *s1,strtype *s2)
{
int t=0;
if(len(s1)<len(s2))
return ;
int i=0;
while(i<len(s1) && s1->ch[i]!=s2->ch[0])
{
i++;
}
if(i==len(s1))
return ;
else if(i<len(s1))
{
search(s1,s2,i);
return ;
}
}
void index(strtype *s1,strtype *s2);
void search(strtype *s1,strtype *s2,int i)
{
if(i>=len(s1))
return ;
else
{
int k=i,j=0;
int m=k;
while(s1->ch[k]==s2->ch[j] && j<=len(s2))
{
k++;
j++;
}
if(j>=len(s2))
{
index(del(s1,m+1,len(s2)),s2);
}
else
search(s1,s2,i+1);
}
}
void index(strtype *s1,strtype *s2)
{
int t=0;
if(len(s1)<len(s2))
return ;
int i=0;
while(i<len(s1) && s1->ch[i]!=s2->ch[0])
{
i++;
}
if(i==len(s1))
return ;
else if(i<len(s1))
{
search(s1,s2,i);
return ;
}
}
相关文章推荐
- 删除字符串中的子串
- 从字符串中删除出现的子串
- 字符串-02. 删除字符串中的子串(20)
- 10-2. 删除字符串中的子串(20)
- 【编程小练习】删除字符串中的子串
- 字符串-02. 删除字符串中的子串(20)
- 安卓从字符串中删除指定的子串
- 7-20 删除字符串中的子串(20 分)
- 删除指定字符串中的子串
- 删除字符串中所有给定的子串
- PAT_B_字符串-02. 删除字符串中的子串(20)
- 字符串删除子串
- 删除原字符串中所有匹配的子串,并返回匹配的子串个数
- PAT 字符串-02 删除字符串中的子串
- jeapedu 31 字符串切片删除子串
- 从一个字符串中删除一个子串后返回该字符串和包含的子串的个数
- 删除字符串中的子串
- 5-29 删除字符串中的子串 (20分)c语言
- PTA 7-29 删除字符串中的子串(20 分)strstr函数应用
- C语言字符串操作--删除子串