# include<stdio.h> #include<iostream> using namespace std; int main(){ string s,tag,sub; while(getline(cin,s)){ cin>>sub; cin>>tag; int index = 0; int count = 0; while((index=s.find(sub,index))<s.length())//迭代 { if((s[index-1]==' '&&s[index+sub.length()]==' ')||(index==0&&s[index+sub.length()]==' ')||(s[index-1]==' '&&index==s.length()-1))//1.单词在中间的情况 2.单词在最开头的情况 3.单词在最末尾的情况 s.replace(index,sub.length(),tag);//替换 (index ,length ,"tag") index++; } cout<<s; } }