1 条题解
-
1
张子瑞 LV 6 @ 2025-07-27 10:52:15
#include <iostream>
#include <string>
using namespace std;int main() {
string story, originalName, newName;// 读取故事内容(包含空格的整行)
getline(cin, story);// 读取原男主名字和新名字
cin >> originalName >> newName;// 处理替换逻辑
size_t pos = 0;
while ((pos = story.find(originalName, pos)) != string::npos) {
story.replace(pos, originalName.length(), newName);
pos += newName.length(); // 移动到替换后的文本之后
}// 输出替换后的故事
cout << story << endl;return 0;
}
- 1
信息
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 495
- 已通过
- 130
- 通过率
- 26%
- 被复制
- 10
- 上传者