#include <iostream>
#include <string>
using namespace std;
void getStr(const string &sub, string &src) {
int l1 = src.size();
int l2 = sub.size();
for (int i = 0; i < l1; ) {
if (sub == src.substr(i, l2)) {
src = src.substr(0, i) + src.substr(i+l2);
l1 = src.size();
}
else {
i++;
}
}
}
int main() {
string str, temp;
cin >> str;
cin >> temp;
getStr(str, temp);
cout << str;
return 0;
}
0、删除源字符串中的所有指定字串,并输出删除后的字符串
于 2023-01-31 21:44:48 首次发布
本文介绍了一个使用C++实现的简单字符串替换算法。该算法通过遍历源字符串并查找子字符串,一旦找到则进行替换操作。文章展示了完整的代码实现过程,并提供了一个简单的输入输出示例。
4864

被折叠的 条评论
为什么被折叠?



