一直因为C++里面没有现成的替换函数而烦恼,只怪自己太懒懒的写
借这题写好这个函数,,以后直接用就好了
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
const int MX = 1e3 + 5;
string Replace(string s, string a, string b, bool Match = false) {
string tmp = s;
if(!Match) {
transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
transform(a.begin(), a.end(), a.begin(), ::tolower);
}
int pos;
while(true) {
if((pos = tmp.find(a)) != -1) {
tmp.replace(pos, a.length(), b);
s.replace(pos, a.length(), b);
} else break;
}
return s;
}
char S[MX], a[MX] = "marshtomp", b[MX] = "fjxmlhx";
int main() {
while(gets(S)) {
printf("%s\n", Replace(string(S), string(a), string(b)).c_str());
}
return 0;
}