求大神用C++写写下面程序,各位大神给点思路吧,跪谢
下面是我自己写的程序
#include <iostream>
#include <string>
using std::cin; using std::cout;
using std::endl; using std::string;
int main()
{
cout<<"请输入一段话:";
string chara;
while(!cin.eof())
cin>>chara;
const string::size_type n=chara.size();
for(int i=0;i<n;++i){
if('A'<=chara[i]&&chara[i]<='Z')
chara[i]+=32;
//回车换行符用空格来替代
if(chara[i]=='\r'||chara[i]=='\n'){
chara[i]=' ';
}
}
//替换bullshit为bush
string nmd="bullshit";
int i=0;
while(i<=n-nmd.size()+1){
chara=chara.replace(chara.find("bullshit"),1,"bush");
++i;
}
for(int i=0;i<chara.size();++i){
int j=1;
while(chara[i]==' '){
++i;
if(chara[i]==' ')
++i;
++j;
}
string space(j,' ');
string s(1,' ');
for(int i=0;i<=chara.size()-j+1;++i)
chara=chara.replace(chara.find(space),1,s);
}
for(int i=0;i<chara.size();++i)
cout<<chara[i];
return 0;
}
[此贴子已经被作者于2016-9-28 13:59编辑过]