#include <iostream> using namespace std; int main() { string str, base, replace;//句子 door key getline(cin, str);//输入一行 str = " " + str + " ";//前后加上空格 getline(cin, base); base = " " + base + " ";//前后加上空格 getline(cin, replace); replace = " " + replace + " ";//前后加上空格 while (str.find(base) != string::npos) {//找得到进入循环 int found = str.find(base); str.erase(found, base.size()); str.insert(found, replace); } cout << str.substr(1, str.size() - 2) << endl;//不输出前后空格 return 0; }