python依旧简单
s1 = input()
s2 = input()
s3 = input()
for word in s1.split(" "):
if word == s2:
print(s3, end=' ')
else:
print(word, end=' ')
自从学了stringstream做字符串就开心多了
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
string s1, s2, s3;
getline(cin, s1);
cin >> s2 >> s3;
stringstream ssin(s1);
string word;
while(ssin >> word)
{
if (word == s2) cout << s3 << ' ';
else cout << word << ' ';
}
return 0;
}