字符串处理(1)
我们接下来要运用学到的字符串的插入和查找函数,对一串文本进行处理。
这一串文本中如果出现某个特定字符串 ,则在这个特定字符串之后插入字符串 hello;否则,将这串文本原样输出。
输入格式
第一行,有空格的字符串 ss
第二行,查询的特定字符串 mm
输出格式
一行处理后的字符串
输入数据
pen pencil penny
pen
输出数据
penhello penhellocil penhellony
```c++
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
string m;
getline(cin,s);
cin>>m;
int len=s.size();
for(int i=0;i<len;i++){
if ( s.find("pen") == string::npos) {
cout << s.insert(3, "hello");
} else {
cout<<s;
return 0;
}
}
return 0;
}