题解 | 单词替换
单词替换
https://www.nowcoder.com/practice/5b58a04679d5419caf62c2b238e5c9c7
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
string str, a, b;
getline(cin, str);
getline(cin, a);
getline(cin, b);
string temp;
stringstream ss(str);
while (getline(ss, temp, ' ')) {
if (temp == a) {
cout << b << " ";
}else {
cout << temp << " ";
}
}
}
// 64 位输出请用 printf("%lld")
这个应该是最简单的了

查看12道真题和解析