AcWing 770. 单词替换
原题链接
中等
作者:
牛奶小柒Luke
,
2021-02-10 17:08:09
,
所有人可见
,
阅读 320
#include <iostream>
#include <cstring>
#include <regex>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
string str,str1,str2;
getline(cin,str);
cin >> str1 >> str2;
cout << regex_replace(str,regex("\\b" + str1 + "\\b"),str2) << endl;
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
int main(){
string s[1100],str1,str2;
int a = 0,b = 0;
while(cin >> s[a]){
a++;
char x = getchar();
if(x == '\n') break;
}
cin >> str1 >> str2;
for(int i = 0;i < a;++i){
if(s[i] == str1) cout << str2 << ' ';
else cout << s[i] << ' ';
}
cout << endl;
return 0;
}