题解 | #单词替换#
单词替换
https://www.nowcoder.com/practice/5b58a04679d5419caf62c2b238e5c9c7
#include <iostream> using namespace std; string s[110], a, b; int main() { int cnt = 0; while(cin >> s[++cnt]){} cnt--; a = s[cnt - 1]; b = s[cnt]; int i; for (i = 1; i <= cnt - 2; i++) { if(s[i] == a) { cout << b << " "; } else { cout << s[i] << " "; } } }