4.12.cpp
来自「严蔚敏数据结构习题C++实现」· C++ 代码 · 共 45 行
CPP
45 行
#include <iostream>
#include <string>
using namespace std;
void Replace(string& S,string T,string V);
int main()
{
string s,t,v;
cin >> s >> t >> v;
Replace(s,t,v);
cout << s;
system("pause");
return 0;
}
void Replace(string& S,string T,string V)
{
char temp[100] = {'\0'};
int mark = 0;
int i = 0;
int j = 0;
bool is_success;
while(S[i] != '\0')
{
is_success = true;
int j = i;
for(int s=0; T[s]!='\0';s++)
{
if(S[j] == T[s])
j++;
else
{is_success = false;break;}
}
if(!is_success)
temp[mark++] = S[i++];
else
{
for(int m=0; V[m]!='\0'; m++)
temp[mark++] = V[m];
i = j;
}
}
S = temp;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?