1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() { 4 string s1, s2; 5 cin >> s1 >> s2; 6 for (int i = 0; i <= s1.length() - s2.length(); i++) { 7 if (s1.substr(i, s2.length()) == s2) { 8 s1.erase(i, s2.length()); 9 i--; //此处一定要减一下 10 } 11 } 12 cout << s1 << endl; 13 return 0; 14 }
原文:https://www.cnblogs.com/fx1998/p/12713940.html