注册 登录
编程论坛 C++教室

c++新人求教一个小问题

njcr7 发布于 2016-09-04 21:50, 1465 次点击
只有本站会员才能查看附件,请 登录
3 回复
#2
stave_72016-09-04 21:56
一个思路:先判断字符,若相同,再判断首尾是否为空
#3
njcr72016-09-04 22:04
回复 2楼 stave_7
思路有,但是不区分大小写想不到怎么办
#4
rjsp2016-09-05 09:16
程序代码:
#include <cctype>

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

void foo( string& s, const string& r )
{
    for( auto itor=s.begin()
        ; itor = search( itor, s.end(), r.begin(), r.end(), [](char a, char b){ return ::toupper(a)==::toupper(b); } )
        , itor!=s.end()
        ; advance(itor,r.size()) )
    {
        if( (itor==s.begin() || ::isspace(*prev(itor))) && (next(itor,r.size())==s.end() || ::isspace(*next(itor,r.size()))) )
        {
            fill( itor, next(itor,r.size()), '*' );
        }
    }
}

int main( void )
{
    string line, word;
    getline( cin, line ) >> word;
    //string line = "Our house is at your disposal";
   
//string word = "our";

    foo( line, word );

    cout << line << endl;
}
1