子串删除
描述
给定两个字符串s和t,若s是t的子串,将t中的子串s删除,若存在多个子串,则全部删除;若s不是t的子串,对字符串t不做处理。字符串s和t长度不超过1000。
输入
第一行,字符串t,文本长度\le≤1000。
第二行,字符串s,文本长度\le≤1000。
输出
处理后的字符串t
输入样例 1
Hello World! Hello
输出样例 1
World!
输入样例 2
Hello World! Ho
输出样例 2
Hello World!
输入样例 3
No pain, no gain ain
输出样例 3
No p, no g
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void StrDelandOutput(char *t,char *s)
{
int n=strlen(s),m=strlen(t);
int temp=1;
char *p=s,*q=t;
for(;*q!='\0';q++)
{
if(strncmp(p,q,n)==0)
{
for(int i=0;*(q+n+i)!=0;i++)
{
*(q+i)=*(q+n+i);
}
*(t+m-n*temp)='\0';
temp++;
q--;
}
}
puts(t);
};
int main()
{
char t[1005],s[1005];
gets(t);
gets(s);
StrDelandOutput(t,s);
return 0;
}