输入2个字符串S1和S2,要求删除字符串S1中出现的所有子串S2,即结果字符串中不能包含S2。
输入格式:
输入在2行中分别给出不超过80个字符长度的、以回车结束的2个非空字符串,对应S1和S2。
输出格式:
在一行中输出删除字符串S1中出现的所有子串S2后的结果字符串。
输入样例:
Tomcat is a male ccatat
cat
输出样例:
Tom is a male
#include<stdio.h>
#include<string.h>
int main()
{
char a[81],b[81];
gets(a);
gets(b);
char *p;
char c[81];
while(p=strstr(a,b))
{
*p = '\0';
strcpy (c, p+strlen(b));
strcat (a, c);
}
puts(a);
return 0;
}
乍一看是个很难的题目,当你知道<string.h>这个头文件中有巨多好用的函数后,这道题目就简单了不少
strstr(a,b) 检测两个数组重复的部分
strlen(b) 计算字符串长度
strcat (a, c)字符串相加
strcpy (a,b)复制字符串
具体用法自行百度。