#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main(){
char str[101];
gets(str);
string a = str;
for(int i = 0;i<a.size();i++)
a[i] = towlower(a[i]);//全部转成小写字母,方便进行删除
while(gets(str)){
string c = str;
string b = c;//保留原有的字符串
for(int i = 0;i<b.size();i++)
b[i] = towlower(b[i]);
int t = b.find(a,0);//在b中查找a首次出现的位置
while(t!=string::npos){//若有
b.erase(t,a.size());//不能省
c.erase(t,a.size());
t = b.find(a,t);
}
//去掉空格
t = c.find(' ',0);
while(t!=string::npos){
c.erase(t,1);
t = c.find(' ',t);
}
cout<<c<<endl;
}
}
字符串中查找删除
最新推荐文章于 2024-01-19 11:22:00 发布