#include <iostream>
using namespace std;
int main()
{
char str[50] = {0};
char subStr[10] = {0};
//输入主串以#结尾
cout<<"input the string:";
for(int i = 0;i<sizeof(str)/sizeof(str[0]);i++)
{
cin>>str[i];
if(str[i] == '#')
{
str[i] = '\0';
break;
}
}
//输入子串以#结尾
cout<<"input the substring:";
for(int i = 0;i<sizeof(subStr)/sizeof(subStr[0]);i++)
{
cin>>subStr[i];
if(subStr[i] == '#')
{
subStr[i] = '\0';
break;
}
}
//用于标记是否找到子串
bool isSub = true;
//找子串
for(int i = 0;i<strlen(str);i++)
{
isSub = true;
for(int j = 0;j<strlen(subStr);j++)
{
if(subStr[j] == str[i+j]) continue;
else
{
isSub = false;
break;
}
}
if(isSub)
{//如果找到子串,则将后续字符全部前移
for(int m = i;m<strlen(str)+1-strlen(subStr);m++)
{
str[m] = str[m+strlen(subStr)];
}
}
}
//输出删除后的
cout<<"the result string:"<<str<<endl;
system("pause");
return 1;
}